2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* 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.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
2020-10-22 03:07:02 +02:00
|
|
|
|
using XenAdmin.Core;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAPI;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs.OptionsPages
|
|
|
|
|
{
|
|
|
|
|
public partial class ConnectionOptionsPage : UserControl, IOptionsPage
|
|
|
|
|
{
|
2020-10-22 01:49:13 +02:00
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2020-10-22 03:07:02 +02:00
|
|
|
|
private readonly ToolTip validationToolTip;
|
|
|
|
|
private Control invalidControl;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-07-04 14:47:24 +02:00
|
|
|
|
// used for preventing the event handlers from doing anything when changing controls through code
|
2020-10-22 03:07:02 +02:00
|
|
|
|
private bool eventsDisabled;
|
2016-06-20 18:15:00 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public ConnectionOptionsPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2020-10-22 03:07:02 +02:00
|
|
|
|
validationToolTip = new ToolTip
|
|
|
|
|
{
|
|
|
|
|
IsBalloon = true,
|
2023-05-11 13:04:44 +02:00
|
|
|
|
ToolTipIcon = ToolTipIcon.Warning
|
2020-10-22 03:07:02 +02:00
|
|
|
|
};
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 03:07:02 +02:00
|
|
|
|
public void Build()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-10-22 03:07:02 +02:00
|
|
|
|
eventsDisabled = true;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// Proxy server
|
2016-10-12 20:09:35 +02:00
|
|
|
|
switch ((HTTPHelper.ProxyStyle)Properties.Settings.Default.ProxySetting)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-10-12 20:09:35 +02:00
|
|
|
|
case HTTPHelper.ProxyStyle.DirectConnection:
|
2013-06-24 13:41:48 +02:00
|
|
|
|
DirectConnectionRadioButton.Checked = true;
|
|
|
|
|
break;
|
2016-10-12 20:09:35 +02:00
|
|
|
|
case HTTPHelper.ProxyStyle.SystemProxy:
|
2013-06-24 13:41:48 +02:00
|
|
|
|
UseIERadioButton.Checked = true;
|
|
|
|
|
break;
|
2016-10-12 20:09:35 +02:00
|
|
|
|
case HTTPHelper.ProxyStyle.SpecifiedProxy:
|
2013-06-24 13:41:48 +02:00
|
|
|
|
UseProxyRadioButton.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DirectConnectionRadioButton.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 18:15:00 +02:00
|
|
|
|
ProxyAddressTextBox.Text = Properties.Settings.Default.ProxyAddress;
|
|
|
|
|
ProxyPortTextBox.Text = Properties.Settings.Default.ProxyPort.ToString();
|
|
|
|
|
BypassForServersCheckbox.Checked = Properties.Settings.Default.BypassProxyForServers;
|
|
|
|
|
|
2017-02-13 21:28:35 +01:00
|
|
|
|
AuthenticationCheckBox.Checked = Properties.Settings.Default.ProvideProxyAuthentication;
|
2016-10-12 20:09:35 +02:00
|
|
|
|
|
2017-02-13 21:28:35 +01:00
|
|
|
|
switch ((HTTP.ProxyAuthenticationMethod)Properties.Settings.Default.ProxyAuthenticationMethod)
|
2016-07-04 14:47:24 +02:00
|
|
|
|
{
|
2017-02-13 21:28:35 +01:00
|
|
|
|
case HTTP.ProxyAuthenticationMethod.Basic:
|
|
|
|
|
BasicRadioButton.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
case HTTP.ProxyAuthenticationMethod.Digest:
|
|
|
|
|
DigestRadioButton.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DigestRadioButton.Checked = true;
|
|
|
|
|
break;
|
2016-07-04 14:47:24 +02:00
|
|
|
|
}
|
2017-02-13 21:28:35 +01:00
|
|
|
|
|
|
|
|
|
// checks for empty default username/password which starts out unencrypted
|
2020-10-22 01:49:13 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string protectedUsername = Properties.Settings.Default.ProxyUsername;
|
|
|
|
|
ProxyUsernameTextBox.Text = string.IsNullOrEmpty(protectedUsername) ? "" : EncryptionUtils.Unprotect(protectedUsername);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Warn("Could not unprotect internet proxy username.", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string protectedPassword = Properties.Settings.Default.ProxyPassword;
|
|
|
|
|
ProxyPasswordTextBox.Text = string.IsNullOrEmpty(protectedPassword) ? "" : EncryptionUtils.Unprotect(protectedPassword);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Warn("Could not unprotect internet proxy password.", e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-04 17:22:29 +02:00
|
|
|
|
ConnectionTimeoutNud.Value = (decimal) Properties.Settings.Default.ConnectionTimeout / 1000;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-07-05 11:40:21 +02:00
|
|
|
|
eventsDisabled = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 18:15:00 +02:00
|
|
|
|
private void AuthenticationCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-07-05 11:40:21 +02:00
|
|
|
|
if (eventsDisabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
eventsDisabled = true;
|
|
|
|
|
|
|
|
|
|
if (!AuthenticationCheckBox.Checked)
|
|
|
|
|
{
|
|
|
|
|
ProxyUsernameTextBox.Clear();
|
|
|
|
|
ProxyPasswordTextBox.Clear();
|
|
|
|
|
}
|
|
|
|
|
SelectUseThisProxyServer();
|
|
|
|
|
|
|
|
|
|
eventsDisabled = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 16:28:17 +02:00
|
|
|
|
private void GeneralProxySettingsChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-07-05 11:40:21 +02:00
|
|
|
|
if (eventsDisabled)
|
|
|
|
|
return;
|
|
|
|
|
SelectUseThisProxyServer();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 16:28:17 +02:00
|
|
|
|
private void ProxyAuthenticationSettingsChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-07-05 11:40:21 +02:00
|
|
|
|
if (eventsDisabled)
|
|
|
|
|
return;
|
|
|
|
|
SelectProvideCredentials();
|
2016-10-12 20:09:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 18:15:00 +02:00
|
|
|
|
private void SelectUseThisProxyServer()
|
|
|
|
|
{
|
2016-07-04 14:47:24 +02:00
|
|
|
|
UseProxyRadioButton.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectProvideCredentials()
|
|
|
|
|
{
|
|
|
|
|
AuthenticationCheckBox.Checked = true;
|
2016-07-05 11:40:21 +02:00
|
|
|
|
UseProxyRadioButton.Checked = true;
|
2016-06-20 18:15:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 03:07:02 +02:00
|
|
|
|
#region IOptionsPage Members
|
|
|
|
|
|
2023-05-11 13:04:44 +02:00
|
|
|
|
public bool IsValidToSave(out Control control, out string invalidReason)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (!UseProxyRadioButton.Checked)
|
|
|
|
|
{
|
2023-05-11 13:04:44 +02:00
|
|
|
|
invalidReason = null;
|
|
|
|
|
control = null;
|
2020-10-22 03:07:02 +02:00
|
|
|
|
return true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-05-11 13:04:44 +02:00
|
|
|
|
|
|
|
|
|
invalidReason = Messages.INVALID_PARAMETER;
|
|
|
|
|
|
2020-10-22 03:07:02 +02:00
|
|
|
|
var uriHostNameType = Uri.CheckHostName(ProxyAddressTextBox.Text);
|
|
|
|
|
if (uriHostNameType == UriHostNameType.Unknown || uriHostNameType == UriHostNameType.IPv6)
|
2016-06-20 18:15:00 +02:00
|
|
|
|
{
|
2023-05-11 13:04:44 +02:00
|
|
|
|
control = ProxyAddressTextBox;
|
2020-10-22 03:07:02 +02:00
|
|
|
|
return false;
|
2016-06-20 18:15:00 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-06-20 12:58:29 +02:00
|
|
|
|
if (!Util.IsValidPort(ProxyPortTextBox.Text))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-05-11 13:04:44 +02:00
|
|
|
|
control = ProxyPortTextBox;
|
2020-10-22 03:07:02 +02:00
|
|
|
|
return false;
|
2020-06-20 12:58:29 +02:00
|
|
|
|
}
|
2014-11-27 16:29:29 +01:00
|
|
|
|
|
2020-10-22 03:07:02 +02:00
|
|
|
|
if (AuthenticationCheckBox.Checked && string.IsNullOrEmpty(ProxyUsernameTextBox.Text))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-05-11 13:04:44 +02:00
|
|
|
|
control = ProxyUsernameTextBox;
|
2020-10-22 03:07:02 +02:00
|
|
|
|
return false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-10-22 03:07:02 +02:00
|
|
|
|
|
2023-05-11 13:04:44 +02:00
|
|
|
|
control = null;
|
2020-10-22 03:07:02 +02:00
|
|
|
|
return true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-11 13:04:44 +02:00
|
|
|
|
public void ShowValidationMessages(Control control, string message)
|
2020-10-22 03:07:02 +02:00
|
|
|
|
{
|
2023-05-11 13:04:44 +02:00
|
|
|
|
if (control != null && !string.IsNullOrEmpty(message))
|
|
|
|
|
{
|
|
|
|
|
invalidControl = control;
|
|
|
|
|
validationToolTip.ToolTipTitle = message;
|
|
|
|
|
HelpersGUI.ShowBalloonMessage(control, validationToolTip);
|
|
|
|
|
}
|
2020-10-22 03:07:02 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-23 11:34:46 +02:00
|
|
|
|
public void HideValidationMessages()
|
|
|
|
|
{
|
2023-05-11 13:04:44 +02:00
|
|
|
|
if (invalidControl != null)
|
|
|
|
|
validationToolTip.Hide(invalidControl);
|
2021-08-23 11:34:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public void Save()
|
|
|
|
|
{
|
2016-06-20 18:15:00 +02:00
|
|
|
|
// Proxy server settings
|
2013-06-24 13:41:48 +02:00
|
|
|
|
HTTPHelper.ProxyStyle new_proxy_style =
|
2020-10-22 01:49:13 +02:00
|
|
|
|
DirectConnectionRadioButton.Checked
|
|
|
|
|
? HTTPHelper.ProxyStyle.DirectConnection
|
|
|
|
|
: UseIERadioButton.Checked
|
|
|
|
|
? HTTPHelper.ProxyStyle.SystemProxy
|
|
|
|
|
: HTTPHelper.ProxyStyle.SpecifiedProxy;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (Properties.Settings.Default.ProxySetting != (int)new_proxy_style)
|
|
|
|
|
Properties.Settings.Default.ProxySetting = (int)new_proxy_style;
|
|
|
|
|
|
2016-06-20 18:15:00 +02:00
|
|
|
|
if (ProxyAddressTextBox.Text != Properties.Settings.Default.ProxyAddress && !string.IsNullOrEmpty(ProxyAddressTextBox.Text))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Properties.Settings.Default.ProxyAddress = ProxyAddressTextBox.Text;
|
|
|
|
|
|
2017-02-13 21:28:35 +01:00
|
|
|
|
Properties.Settings.Default.ProxyUsername = EncryptionUtils.Protect(ProxyUsernameTextBox.Text);
|
|
|
|
|
Properties.Settings.Default.ProxyPassword = EncryptionUtils.Protect(ProxyPasswordTextBox.Text);
|
|
|
|
|
Properties.Settings.Default.ProvideProxyAuthentication = AuthenticationCheckBox.Checked;
|
|
|
|
|
|
2020-10-22 01:49:13 +02:00
|
|
|
|
HTTP.ProxyAuthenticationMethod new_auth_method = BasicRadioButton.Checked
|
|
|
|
|
? HTTP.ProxyAuthenticationMethod.Basic
|
|
|
|
|
: HTTP.ProxyAuthenticationMethod.Digest;
|
|
|
|
|
|
2017-02-13 21:28:35 +01:00
|
|
|
|
if (Properties.Settings.Default.ProxyAuthenticationMethod != (int)new_auth_method)
|
|
|
|
|
Properties.Settings.Default.ProxyAuthenticationMethod = (int)new_auth_method;
|
2016-06-20 18:15:00 +02:00
|
|
|
|
|
2020-10-22 01:49:13 +02:00
|
|
|
|
if (int.TryParse(ProxyPortTextBox.Text, out int port))
|
2016-06-20 18:15:00 +02:00
|
|
|
|
{
|
|
|
|
|
if (port != Properties.Settings.Default.ProxyPort)
|
|
|
|
|
Properties.Settings.Default.ProxyPort = port;
|
|
|
|
|
}
|
2020-10-22 01:49:13 +02:00
|
|
|
|
else
|
2016-06-20 18:15:00 +02:00
|
|
|
|
Properties.Settings.Default.ProxyPort = 80;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-06-20 18:15:00 +02:00
|
|
|
|
if (BypassForServersCheckbox.Checked != Properties.Settings.Default.BypassProxyForServers)
|
|
|
|
|
Properties.Settings.Default.BypassProxyForServers = BypassForServersCheckbox.Checked;
|
|
|
|
|
|
|
|
|
|
// timeout settings
|
2020-10-22 01:49:13 +02:00
|
|
|
|
int timeout = 1000* (int)ConnectionTimeoutNud.Value;
|
|
|
|
|
if (timeout != Properties.Settings.Default.ConnectionTimeout)
|
|
|
|
|
Properties.Settings.Default.ConnectionTimeout = timeout;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2022-11-11 14:57:37 +01:00
|
|
|
|
Settings.ReconfigureProxyAuthenticationSettings();
|
2021-08-23 11:34:46 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2018-03-20 18:02:45 +01:00
|
|
|
|
#region IVerticalTab Members
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-06-20 12:58:29 +02:00
|
|
|
|
public override string Text => Messages.CONNECTION;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-06-20 12:58:29 +02:00
|
|
|
|
public string SubText => Messages.CONNECTION_DESC;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-06-18 02:20:29 +02:00
|
|
|
|
public Image Image => Images.StaticImages._000_Network_h32bit_16;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|