mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
CP-13848: XenCenter transfers proxy settings to HealthCheckService.
Signed-off-by: Hui Zhang <hui.zhang@citrix.com>
This commit is contained in:
parent
8eb5aef92a
commit
0761aa5be2
@ -37,6 +37,7 @@ using System.Data;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using XenAdmin.Properties;
|
||||
using XenAdmin.Actions;
|
||||
using XenAPI;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@ -182,6 +183,12 @@ namespace XenAdmin.Dialogs.OptionsPages
|
||||
}
|
||||
|
||||
Program.ReconfigureConnectionSettings();
|
||||
new TransferProxySettingsAction((HTTPHelper.ProxyStyle)Properties.Settings.Default.ProxySetting,
|
||||
Properties.Settings.Default.ProxyAddress,
|
||||
Properties.Settings.Default.ProxyPort,
|
||||
Properties.Settings.Default.ConnectionTimeout,
|
||||
Properties.Settings.Default.BypassProxyForLocal,
|
||||
true).RunAsync();
|
||||
}
|
||||
|
||||
private void SetSpecifiedProxySettings()
|
||||
|
@ -495,6 +495,12 @@ namespace XenAdmin
|
||||
try
|
||||
{
|
||||
Settings.RestoreSession();
|
||||
new TransferProxySettingsAction((HTTPHelper.ProxyStyle)Properties.Settings.Default.ProxySetting,
|
||||
Properties.Settings.Default.ProxyAddress,
|
||||
Properties.Settings.Default.ProxyPort,
|
||||
Properties.Settings.Default.ConnectionTimeout,
|
||||
Properties.Settings.Default.BypassProxyForLocal,
|
||||
true).RunAsync();
|
||||
}
|
||||
catch (ConfigurationErrorsException ex)
|
||||
{
|
||||
|
@ -102,7 +102,7 @@ namespace XenAdmin.Actions
|
||||
credential = ProtectCredential(host.address, username, password);
|
||||
else
|
||||
credential = ProtectCredential(host.address, string.Empty, string.Empty);
|
||||
pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length);
|
||||
pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, (Encoding.UTF8.GetBytes(credential)).Length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
122
XenModel/Actions/HealthCheck/TransferProxySettingsAction.cs
Normal file
122
XenModel/Actions/HealthCheck/TransferProxySettingsAction.cs
Normal file
@ -0,0 +1,122 @@
|
||||
/* Copyright (c) Citrix Systems Inc.
|
||||
* 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.IO.Pipes;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using XenAPI;
|
||||
|
||||
namespace XenAdmin.Actions
|
||||
{
|
||||
public class TransferProxySettingsAction : PureAsyncAction
|
||||
{
|
||||
private HTTPHelper.ProxyStyle proxyStyle;
|
||||
private string proxyAddress;
|
||||
private int proxyPort;
|
||||
private int timeOut;
|
||||
private bool bypassForLocal;
|
||||
|
||||
public TransferProxySettingsAction(HTTPHelper.ProxyStyle style, string address, int port, int timeout, bool bypassLocal, bool suppressHistory)
|
||||
: base(null, Messages.ACTION_TRANSFER_HEALTHCHECK_SETTINGS, Messages.ACTION_TRANSFER_HEALTHCHECK_SETTINGS, suppressHistory)
|
||||
{
|
||||
proxyStyle = style;
|
||||
proxyAddress = address;
|
||||
proxyPort = port;
|
||||
timeOut = timeout;
|
||||
bypassForLocal = bypassLocal;
|
||||
}
|
||||
|
||||
private const string HEALTHCHECKSERVICENAME = "XenServerHealthCheck";
|
||||
private const char SEPARATOR = '\x202f'; // narrow non-breaking space.
|
||||
|
||||
private string getProxySettings()
|
||||
{
|
||||
string proxySettings;
|
||||
switch (proxyStyle)
|
||||
{
|
||||
case HTTPHelper.ProxyStyle.SpecifiedProxy:
|
||||
proxySettings = String.Join(SEPARATOR.ToString(), new[] {
|
||||
HealthCheckSettings.PROXY_SETTINGS,
|
||||
((Int32)HTTPHelper.ProxyStyle.SpecifiedProxy).ToString(),
|
||||
proxyAddress,
|
||||
proxyPort.ToString(),
|
||||
timeOut.ToString(),
|
||||
bypassForLocal.ToString()});
|
||||
return proxySettings;
|
||||
|
||||
case HTTPHelper.ProxyStyle.SystemProxy:
|
||||
proxySettings = String.Join(SEPARATOR.ToString(), new[] {
|
||||
HealthCheckSettings.PROXY_SETTINGS, ((Int32)HTTPHelper.ProxyStyle.SystemProxy).ToString()});
|
||||
return proxySettings;
|
||||
|
||||
default:
|
||||
proxySettings = String.Join(SEPARATOR.ToString(), new[] {
|
||||
HealthCheckSettings.PROXY_SETTINGS, ((Int32)HTTPHelper.ProxyStyle.DirectConnection).ToString()});
|
||||
return proxySettings;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
{
|
||||
ServiceController sc = new ServiceController(HEALTHCHECKSERVICENAME);
|
||||
if (sc.Status != ServiceControllerStatus.Running)
|
||||
return;
|
||||
|
||||
NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out);
|
||||
int retryCount = 120;
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
pipeClient.Connect(0);
|
||||
}
|
||||
catch (System.TimeoutException exp)
|
||||
{
|
||||
throw exp;
|
||||
}
|
||||
catch
|
||||
{
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
pipeClient = null;
|
||||
pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out);
|
||||
}
|
||||
} while (!pipeClient.IsConnected && retryCount-- != 0);
|
||||
|
||||
byte[] proxy = Encoding.UTF8.GetBytes(getProxySettings());
|
||||
pipeClient.Write(proxy, 0, proxy.Length);
|
||||
|
||||
byte[] endMsg = Encoding.UTF8.GetBytes(HealthCheckSettings.HEALTH_CHECK_PIPE_END_MESSAGE);
|
||||
pipeClient.Write(endMsg, 0, endMsg.Length);
|
||||
pipeClient.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -473,6 +473,7 @@ namespace XenAPI
|
||||
public const string HEALTH_CHECK_PIPE = "HealthCheckServicePipe";
|
||||
public const string HEALTH_CHECK_PIPE_END_MESSAGE = "HealthCheckServicePipe";
|
||||
public const string UPLOAD_UUID = "UploadUuid";
|
||||
public const string PROXY_SETTINGS = "ProxySettings";
|
||||
|
||||
public HealthCheckSettings(HealthCheckStatus status, int intervalInDays, DayOfWeek dayOfWeek, int timeOfDay, int retryInterval)
|
||||
{
|
||||
|
@ -62,6 +62,7 @@
|
||||
<Compile Include="Actions\HealthCheck\HealthCheckAuthenticationAction.cs" />
|
||||
<Compile Include="Actions\HealthCheck\SaveHealthCheckSettingsAction.cs" />
|
||||
<Compile Include="Actions\HealthCheck\TransferHealthCheckSettingAction.cs" />
|
||||
<Compile Include="Actions\HealthCheck\TransferProxySettingsAction.cs" />
|
||||
<Compile Include="Actions\HealthCheck\UploadServerStatusReportAction.cs" />
|
||||
<Compile Include="Actions\HealthCheck\XenServerHealthCheckUpload.cs" />
|
||||
<Compile Include="Actions\CancellingAction.cs" />
|
||||
|
@ -114,10 +114,17 @@ namespace XenServerHealthCheck
|
||||
byteCount = pipeServer.Read(msgBuff, 0, pipeBufferSize);
|
||||
mb.Append(Encoding.UTF8.GetString(msgBuff, 0, byteCount));
|
||||
} while (!(pipeServer.IsMessageComplete));
|
||||
string credential = mb.ToString();
|
||||
if (credential == HealthCheckSettings.HEALTH_CHECK_PIPE_END_MESSAGE)
|
||||
string message = mb.ToString();
|
||||
if (message == HealthCheckSettings.HEALTH_CHECK_PIPE_END_MESSAGE)
|
||||
break;
|
||||
ServerListHelper.instance.UpdateServerCredential(credential);
|
||||
if (message.StartsWith(HealthCheckSettings.PROXY_SETTINGS))
|
||||
{
|
||||
ServerListHelper.instance.UpdateProxy(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerListHelper.instance.UpdateServerCredential(message);
|
||||
}
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ using System.Collections.Generic;
|
||||
using XenAdmin.Core;
|
||||
using XenAdmin.Network;
|
||||
using System.Threading.Tasks;
|
||||
using XenAPI;
|
||||
|
||||
namespace XenServerHealthCheck
|
||||
{
|
||||
@ -42,7 +43,7 @@ namespace XenServerHealthCheck
|
||||
public string HostName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public Task task { get; set; }
|
||||
public System.Threading.Tasks.Task task { get; set; }
|
||||
}
|
||||
|
||||
public class ServerListHelper
|
||||
@ -149,7 +150,7 @@ namespace XenServerHealthCheck
|
||||
{
|
||||
if (decryptCredentialComps.Length == 3)
|
||||
{//Add credential
|
||||
Task originalTask = null;
|
||||
System.Threading.Tasks.Task originalTask = null;
|
||||
foreach (ServerInfo connection in serverList)
|
||||
{
|
||||
if (connection.HostName == decryptCredentialComps[0])
|
||||
@ -184,5 +185,40 @@ namespace XenServerHealthCheck
|
||||
updateServerList();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateProxy(string proxy)
|
||||
{
|
||||
log.Info("Receive proxy update message");
|
||||
|
||||
try
|
||||
{
|
||||
string[] proxySettings = proxy.Split(SEPARATOR);
|
||||
HTTPHelper.ProxyStyle proxyStyle = (HTTPHelper.ProxyStyle)Int32.Parse(proxySettings[1]);
|
||||
|
||||
switch (proxyStyle)
|
||||
{
|
||||
case HTTPHelper.ProxyStyle.SpecifiedProxy:
|
||||
Properties.Settings.Default.ProxySetting = (Int32)proxyStyle;
|
||||
Properties.Settings.Default.ProxyAddress = proxySettings[2];
|
||||
Properties.Settings.Default.ProxyPort = Int32.Parse(proxySettings[3]);
|
||||
Properties.Settings.Default.ConnectionTimeout = Int32.Parse(proxySettings[4]);
|
||||
Properties.Settings.Default.BypassProxyForLocal = bool.Parse(proxySettings[5]);
|
||||
return;
|
||||
|
||||
case HTTPHelper.ProxyStyle.SystemProxy:
|
||||
Properties.Settings.Default.ProxySetting = (Int32)proxyStyle;
|
||||
return;
|
||||
|
||||
default:
|
||||
Properties.Settings.Default.ProxySetting = (Int32)proxyStyle;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Error("Error parsing 'ProxySetting' from XenCenter", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user