2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +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.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Properties;
|
2015-08-24 13:51:46 +02:00
|
|
|
|
using XenAdmin.Actions;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAPI;
|
2016-06-20 18:15:00 +02:00
|
|
|
|
using XenAdmin.Core;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs.OptionsPages
|
|
|
|
|
{
|
|
|
|
|
public partial class ConnectionOptionsPage : UserControl, IOptionsPage
|
|
|
|
|
{
|
|
|
|
|
private const string ConnectionTabSettingsHeader = "Connection Tab Settings -";
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
private OptionsDialog optionsDialog;
|
|
|
|
|
|
2016-07-04 14:47:24 +02:00
|
|
|
|
// used for preventing the event handlers from doing anything when changing controls through code
|
2016-07-05 11:40:21 +02:00
|
|
|
|
private bool eventsDisabled = true;
|
2016-06-20 18:15:00 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public ConnectionOptionsPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OptionsDialog OptionsDialog
|
|
|
|
|
{
|
|
|
|
|
set { this.optionsDialog = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void build()
|
|
|
|
|
{
|
|
|
|
|
// 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;
|
|
|
|
|
|
2016-07-04 14:47:24 +02:00
|
|
|
|
if (Registry.ProxyAuthenticationEnabled)
|
|
|
|
|
{
|
|
|
|
|
AuthenticationCheckBox.Checked = Properties.Settings.Default.ProvideProxyAuthentication;
|
2016-10-12 20:09:35 +02:00
|
|
|
|
|
2017-01-20 15:47:04 +01:00
|
|
|
|
switch ((HTTP.ProxyAuthenticationMethod)Properties.Settings.Default.ProxyAuthenticationMethod)
|
2016-10-12 20:09:35 +02:00
|
|
|
|
{
|
2017-01-20 15:47:04 +01:00
|
|
|
|
case HTTP.ProxyAuthenticationMethod.Basic:
|
2016-10-12 20:09:35 +02:00
|
|
|
|
BasicRadioButton.Checked = true;
|
|
|
|
|
break;
|
2017-01-20 15:47:04 +01:00
|
|
|
|
case HTTP.ProxyAuthenticationMethod.Digest:
|
2016-10-12 20:09:35 +02:00
|
|
|
|
DigestRadioButton.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DigestRadioButton.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-06-20 18:15:00 +02:00
|
|
|
|
|
2016-07-04 14:47:24 +02:00
|
|
|
|
// checks for empty default username/password which starts out unencrypted
|
|
|
|
|
string protectedUsername = Properties.Settings.Default.ProxyUsername;
|
|
|
|
|
ProxyUsernameTextBox.Text = string.IsNullOrEmpty(protectedUsername) ? "" : EncryptionUtils.Unprotect(Properties.Settings.Default.ProxyUsername);
|
|
|
|
|
string protectedPassword = Properties.Settings.Default.ProxyPassword;
|
|
|
|
|
ProxyPasswordTextBox.Text = string.IsNullOrEmpty(protectedPassword) ? "" : EncryptionUtils.Unprotect(Properties.Settings.Default.ProxyPassword);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// hide controls
|
|
|
|
|
AuthenticationCheckBox.Visible = false;
|
|
|
|
|
ProxyUsernameLabel.Visible = false;
|
|
|
|
|
ProxyUsernameTextBox.Visible = false;
|
|
|
|
|
ProxyPasswordLabel.Visible = false;
|
|
|
|
|
ProxyPasswordTextBox.Visible = false;
|
2016-10-12 20:09:35 +02:00
|
|
|
|
AuthenticationMethodPanel.Visible = false;
|
|
|
|
|
AuthenticationMethodLabel.Visible = false;
|
2016-07-04 14:47:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 18:15:00 +02:00
|
|
|
|
ConnectionTimeoutNud.Value = 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UseProxyRadioButton_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-07-05 11:40:21 +02:00
|
|
|
|
if (eventsDisabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-06-20 18:15:00 +02:00
|
|
|
|
enableOK();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
enableOK();
|
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();
|
|
|
|
|
enableOK();
|
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
|
|
|
|
enableOK();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void enableOK()
|
|
|
|
|
{
|
|
|
|
|
if (optionsDialog == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!UseProxyRadioButton.Checked)
|
|
|
|
|
{
|
|
|
|
|
optionsDialog.okButton.Enabled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-20 18:15:00 +02:00
|
|
|
|
else if (AuthenticationCheckBox.Checked && string.IsNullOrEmpty(ProxyUsernameTextBox.Text))
|
|
|
|
|
{
|
|
|
|
|
optionsDialog.okButton.Enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-11-27 16:29:29 +01:00
|
|
|
|
if (!Util.IsValidPort(ProxyPortTextBox.Text))
|
|
|
|
|
{
|
|
|
|
|
optionsDialog.okButton.Enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 14:13:01 +02:00
|
|
|
|
var uriHostNameType = Uri.CheckHostName(ProxyAddressTextBox.Text);
|
|
|
|
|
|
|
|
|
|
optionsDialog.okButton.Enabled = uriHostNameType != UriHostNameType.Unknown && uriHostNameType != UriHostNameType.IPv6;
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
optionsDialog.okButton.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Log()
|
|
|
|
|
{
|
|
|
|
|
log.Info(ConnectionTabSettingsHeader);
|
|
|
|
|
// Proxy server
|
|
|
|
|
log.Info("=== ProxySetting: " + Properties.Settings.Default.ProxySetting.ToString());
|
|
|
|
|
log.Info("=== ProxyAddress: " + Properties.Settings.Default.ProxyAddress.ToString());
|
|
|
|
|
log.Info("=== ProxyPort: " + Properties.Settings.Default.ProxyPort.ToString());
|
2016-06-20 18:15:00 +02:00
|
|
|
|
log.Info("=== ByPassProxyForServers: " + Properties.Settings.Default.BypassProxyForServers.ToString());
|
|
|
|
|
log.Info("=== ProvideProxyAuthentication: " + Properties.Settings.Default.ProvideProxyAuthentication.ToString());
|
2016-10-12 20:09:35 +02:00
|
|
|
|
log.Info("=== ProxyAuthenticationMethod: " + Properties.Settings.Default.ProxyAuthenticationMethod.ToString());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
log.Info("=== ConnectionTimeout: " + Properties.Settings.Default.ConnectionTimeout.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IOptionsPage Members
|
|
|
|
|
|
|
|
|
|
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 =
|
|
|
|
|
DirectConnectionRadioButton.Checked ? HTTPHelper.ProxyStyle.DirectConnection :
|
|
|
|
|
UseIERadioButton.Checked ? HTTPHelper.ProxyStyle.SystemProxy :
|
|
|
|
|
HTTPHelper.ProxyStyle.SpecifiedProxy;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2016-07-04 14:47:24 +02:00
|
|
|
|
if (Registry.ProxyAuthenticationEnabled)
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.ProxyUsername = EncryptionUtils.Protect(ProxyUsernameTextBox.Text);
|
|
|
|
|
Properties.Settings.Default.ProxyPassword = EncryptionUtils.Protect(ProxyPasswordTextBox.Text);
|
|
|
|
|
Properties.Settings.Default.ProvideProxyAuthentication = AuthenticationCheckBox.Checked;
|
2016-10-12 20:09:35 +02:00
|
|
|
|
|
2017-01-20 15:47:04 +01:00
|
|
|
|
HTTP.ProxyAuthenticationMethod new_auth_method = BasicRadioButton.Checked ?
|
|
|
|
|
HTTP.ProxyAuthenticationMethod.Basic : HTTP.ProxyAuthenticationMethod.Digest;
|
2016-10-12 20:09:35 +02:00
|
|
|
|
if (Properties.Settings.Default.ProxyAuthenticationMethod != (int)new_auth_method)
|
|
|
|
|
Properties.Settings.Default.ProxyAuthenticationMethod = (int)new_auth_method;
|
2016-07-04 14:47:24 +02:00
|
|
|
|
}
|
2016-06-20 18:15:00 +02:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int port = int.Parse(ProxyPortTextBox.Text);
|
|
|
|
|
if (port != Properties.Settings.Default.ProxyPort)
|
|
|
|
|
Properties.Settings.Default.ProxyPort = port;
|
|
|
|
|
}
|
|
|
|
|
catch
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
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
|
2013-06-24 13:41:48 +02:00
|
|
|
|
int timeout = (int)ConnectionTimeoutNud.Value;
|
|
|
|
|
if (timeout * 1000 != Properties.Settings.Default.ConnectionTimeout)
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.ConnectionTimeout = timeout * 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Program.ReconfigureConnectionSettings();
|
2016-10-12 20:09:35 +02:00
|
|
|
|
new TransferProxySettingsAction(
|
|
|
|
|
(HTTPHelper.ProxyStyle)Properties.Settings.Default.ProxySetting,
|
|
|
|
|
Properties.Settings.Default.ProxyAddress,
|
|
|
|
|
Properties.Settings.Default.ProxyPort,
|
|
|
|
|
Properties.Settings.Default.ConnectionTimeout,
|
|
|
|
|
false,
|
|
|
|
|
Properties.Settings.Default.BypassProxyForServers,
|
|
|
|
|
Properties.Settings.Default.ProvideProxyAuthentication,
|
|
|
|
|
Properties.Settings.Default.ProxyUsername,
|
|
|
|
|
Properties.Settings.Default.ProxyPassword,
|
2017-01-20 15:47:04 +01:00
|
|
|
|
(HTTP.ProxyAuthenticationMethod)Properties.Settings.Default.ProxyAuthenticationMethod).RunAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region VerticalTab Members
|
|
|
|
|
|
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get { return Messages.CONNECTION; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SubText
|
|
|
|
|
{
|
|
|
|
|
get { return Messages.CONNECTION_DESC; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Image Image
|
|
|
|
|
{
|
|
|
|
|
get { return Resources._000_Network_h32bit_16; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|