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.Text.RegularExpressions;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Actions;
|
2019-03-21 14:35:26 +01:00
|
|
|
|
using XenAdmin.Core;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.SettingsPanels
|
|
|
|
|
{
|
|
|
|
|
public partial class LogDestinationEditPage : UserControl, IEditPage
|
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
private Host _host;
|
|
|
|
|
private bool _validToSave;
|
|
|
|
|
private string _origLocation;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
private Regex regex = new Regex(@"^[a-zA-Z0-9]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9])?)*$");
|
|
|
|
|
|
|
|
|
|
private readonly ToolTip InvalidParamToolTip;
|
|
|
|
|
|
|
|
|
|
public LogDestinationEditPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-03-16 02:50:45 +01:00
|
|
|
|
label3.Text = string.Format(label3.Text, BrandManager.ProductBrand);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
Text = Messages.LOG_DESTINATION;
|
|
|
|
|
|
2019-03-21 14:35:26 +01:00
|
|
|
|
InvalidParamToolTip = new ToolTip
|
|
|
|
|
{
|
|
|
|
|
IsBalloon = true,
|
|
|
|
|
ToolTipIcon = ToolTipIcon.Warning,
|
|
|
|
|
ToolTipTitle = Messages.INVALID_PARAMETER
|
|
|
|
|
};
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 14:35:26 +01:00
|
|
|
|
private string RemoteServer => ServerTextBox.Text.Trim();
|
|
|
|
|
|
|
|
|
|
#region IVerticalTabs implementation
|
|
|
|
|
|
2020-06-18 02:20:29 +02:00
|
|
|
|
public Image Image => Images.StaticImages.log_destination_16;
|
2019-03-21 14:35:26 +01:00
|
|
|
|
|
|
|
|
|
public string SubText
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return checkBoxRemote.Checked
|
|
|
|
|
? string.Format(Messages.HOST_LOG_DESTINATION_LOCAL_AND_REMOTE, RemoteServer)
|
|
|
|
|
: Messages.HOST_LOG_DESTINATION_LOCAL;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 14:35:26 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void Repopulate()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
if (_host == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_origLocation = _host.GetSysLogDestination();
|
|
|
|
|
checkBoxRemote.Checked = !string.IsNullOrWhiteSpace(_origLocation);
|
|
|
|
|
ServerTextBox.Text = _origLocation;
|
|
|
|
|
ReValidate();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 14:35:26 +01:00
|
|
|
|
private void ReValidate()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
_validToSave = !checkBoxRemote.Checked ||
|
|
|
|
|
!string.IsNullOrEmpty(RemoteServer) && regex.IsMatch(RemoteServer);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 14:35:26 +01:00
|
|
|
|
#region IEditPage implementation
|
|
|
|
|
|
|
|
|
|
public void SetXenObjects(IXenObject orig, IXenObject clone)
|
|
|
|
|
{
|
|
|
|
|
_host = clone as Host;
|
|
|
|
|
Repopulate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ValidToSave => _validToSave;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public bool HasChanged
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
if (checkBoxRemote.Checked)
|
|
|
|
|
return _origLocation != RemoteServer;
|
|
|
|
|
|
|
|
|
|
return !string.IsNullOrWhiteSpace(_origLocation);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AsyncAction SaveSettings()
|
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
if (_host == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return null;
|
2019-03-21 14:35:26 +01:00
|
|
|
|
|
|
|
|
|
_host.SetSysLogDestination(checkBoxRemote.Checked ? RemoteServer : null);
|
|
|
|
|
|
|
|
|
|
return new DelegatedAsyncAction(
|
|
|
|
|
_host.Connection,
|
|
|
|
|
Messages.ACTION_CHANGE_LOG_DESTINATION,
|
|
|
|
|
string.Format(Messages.ACTION_CHANGING_LOG_DESTINATION_FOR, _host),
|
|
|
|
|
null,
|
|
|
|
|
delegate(Session session) { Host.syslog_reconfigure(session, _host.opaque_ref); },
|
|
|
|
|
true,
|
|
|
|
|
"host.syslog_reconfigure"
|
|
|
|
|
);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowLocalValidationMessages()
|
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
if (!_validToSave)
|
2020-10-22 03:07:02 +02:00
|
|
|
|
HelpersGUI.ShowBalloonMessage(ServerTextBox, InvalidParamToolTip, Messages.GENERAL_EDIT_INVALID_REMOTE);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
InvalidParamToolTip.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 14:35:26 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void checkBoxRemote_CheckedChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
ReValidate();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ServerTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
ReValidate();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 14:35:26 +01:00
|
|
|
|
private void ServerTextBox_Enter(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-03-21 14:35:26 +01:00
|
|
|
|
checkBoxRemote.Checked = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|