2016-01-19 16:35:01 +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.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Data;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using Microsoft.Win32;
|
2015-06-26 00:51:11 +02:00
|
|
|
using XenAdmin.Actions;
|
2013-06-24 13:41:48 +02:00
|
|
|
using XenAdmin.Controls;
|
|
|
|
using XenAdmin.Controls.Common;
|
|
|
|
using XenAdmin.Core;
|
2015-07-15 13:21:52 +02:00
|
|
|
using XenAdmin.Dialogs;
|
2015-06-26 00:51:11 +02:00
|
|
|
using Registry = XenAdmin.Core.Registry;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.BugToolWizardFiles
|
|
|
|
{
|
|
|
|
public partial class BugToolPageDestination : XenTabPage
|
|
|
|
{
|
|
|
|
private bool m_buttonNextEnabled;
|
2015-11-03 16:45:59 +01:00
|
|
|
|
|
|
|
private const int TokenExpiration = 86400; // 24 hours
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
public BugToolPageDestination()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
m_textBoxName.Text = string.Format("{0}{1}.zip", Messages.BUGTOOL_FILE_PREFIX, HelpersGUI.DateTimeToString(DateTime.Now, "yyyy-MM-dd-HH-mm-ss", false));
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string initialDirectory = Path.GetDirectoryName(Properties.Settings.Default.ServerStatusPath);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(initialDirectory) && Directory.Exists(initialDirectory))
|
|
|
|
m_textBoxLocation.Text = initialDirectory;
|
|
|
|
}
|
|
|
|
catch (ArgumentException)
|
|
|
|
{
|
|
|
|
//this is normal; ignore
|
|
|
|
}
|
2016-01-25 09:23:31 +01:00
|
|
|
usernameTextBox.Visible = usernameLabel.Visible = passwordLabel.Visible = passwordTextBox.Visible =
|
|
|
|
caseNumberLabel.Visible = caseNumberTextBox.Visible = optionalLabel.Visible =
|
2016-01-28 22:43:15 +01:00
|
|
|
richTextBox1.Visible = uploadCheckBox.Visible = !HiddenFeatures.UploadOptionHidden;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string Text { get { return Messages.BUGTOOL_PAGE_DESTINATION_TEXT; } }
|
|
|
|
|
|
|
|
public override string PageTitle { get { return Messages.BUGTOOL_PAGE_DESTINATION_PAGETITLE; } }
|
|
|
|
|
|
|
|
public override string HelpID { get { return "ReportDestination"; } }
|
|
|
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
{
|
|
|
|
return m_buttonNextEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void PageLoaded(PageLoadedDirection direction)
|
|
|
|
{
|
|
|
|
base.PageLoaded(direction);
|
2015-06-26 00:51:11 +02:00
|
|
|
PerformCheck(CheckPathValid, CheckCredentialsEntered);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
|
|
|
|
{
|
|
|
|
if (direction == PageLoadedDirection.Forward)
|
2015-06-26 00:51:11 +02:00
|
|
|
cancel = !PerformCheck(CheckPathValid, CheckCredentialsEntered, CheckUploadAuthentication);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
base.PageLeave(direction, ref cancel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public string OutputFile
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var name = m_textBoxName.Text.Trim();
|
|
|
|
var folder = m_textBoxLocation.Text.Trim();
|
|
|
|
if (!name.EndsWith(".zip"))
|
|
|
|
name = string.Concat(name, ".zip");
|
|
|
|
|
|
|
|
return string.Format(@"{0}\{1}", folder, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 00:51:11 +02:00
|
|
|
public bool Upload
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2015-08-20 14:20:35 +02:00
|
|
|
return uploadCheckBox.Checked;
|
2015-06-26 00:51:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string UploadToken { get; private set; }
|
|
|
|
|
2015-11-03 16:45:59 +01:00
|
|
|
public string CaseNumber
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return caseNumberTextBox.Text.Trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
private bool PerformCheck(params CheckDelegate[] checks)
|
|
|
|
{
|
|
|
|
bool success = m_ctrlError.PerformCheck(checks);
|
|
|
|
m_buttonNextEnabled = success;
|
|
|
|
OnPageUpdated();
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CheckPathValid(out string error)
|
|
|
|
{
|
|
|
|
error = string.Empty;
|
|
|
|
|
|
|
|
var name = m_textBoxName.Text.Trim();
|
|
|
|
var folder = m_textBoxLocation.Text.Trim();
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!PathValidator.IsFileNameValid(name))
|
|
|
|
{
|
|
|
|
error = Messages.BUGTOOL_PAGE_DESTINATION_INVALID_NAME;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(folder))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string path = String.Format("{0}\\{1}", folder, name);
|
|
|
|
|
|
|
|
if (!PathValidator.IsPathValid(path))
|
|
|
|
{
|
|
|
|
error = Messages.BUGTOOL_PAGE_DESTINATION_INVALID_FOLDER;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 00:51:11 +02:00
|
|
|
private bool CheckCredentialsEntered(out string error)
|
|
|
|
{
|
|
|
|
error = string.Empty;
|
|
|
|
|
2015-06-30 12:53:11 +02:00
|
|
|
if (!uploadCheckBox.Checked)
|
2015-06-26 00:51:11 +02:00
|
|
|
return true;
|
|
|
|
|
2015-11-04 13:06:52 +01:00
|
|
|
if (string.IsNullOrEmpty(usernameTextBox.Text.Trim()) || string.IsNullOrEmpty(passwordTextBox.Text))
|
2015-06-26 00:51:11 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CheckUploadAuthentication(out string error)
|
|
|
|
{
|
|
|
|
error = string.Empty;
|
|
|
|
|
2015-06-30 12:53:11 +02:00
|
|
|
if (!uploadCheckBox.Checked)
|
2015-06-26 00:51:11 +02:00
|
|
|
return true;
|
|
|
|
|
2015-11-04 13:06:52 +01:00
|
|
|
if (string.IsNullOrEmpty(usernameTextBox.Text.Trim()) || string.IsNullOrEmpty(passwordTextBox.Text))
|
2015-06-26 00:51:11 +02:00
|
|
|
return false;
|
|
|
|
|
2015-09-03 12:49:53 +02:00
|
|
|
var action = new HealthCheckAuthenticationAction(usernameTextBox.Text.Trim(), passwordTextBox.Text.Trim(),
|
2015-08-27 01:30:02 +02:00
|
|
|
Registry.HealthCheckIdentityTokenDomainName, Registry.HealthCheckUploadGrantTokenDomainName,
|
|
|
|
Registry.HealthCheckUploadTokenDomainName, Registry.HealthCheckDiagnosticDomainName, Registry.HealthCheckProductKey,
|
2015-09-03 12:49:53 +02:00
|
|
|
TokenExpiration, false);
|
2015-06-26 00:51:11 +02:00
|
|
|
|
2016-06-20 14:17:42 +02:00
|
|
|
using (var dlg = new ActionProgressDialog(action, ProgressBarStyle.Blocks))
|
|
|
|
dlg.ShowDialog(Parent);
|
2015-07-15 13:21:52 +02:00
|
|
|
|
|
|
|
if (!action.Succeeded)
|
2015-06-26 00:51:11 +02:00
|
|
|
{
|
|
|
|
error = action.Exception != null ? action.Exception.Message : Messages.ERROR_UNKNOWN;
|
|
|
|
UploadToken = null;
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-30 12:53:11 +02:00
|
|
|
|
2015-06-26 00:51:11 +02:00
|
|
|
UploadToken = action.UploadToken; // curent upload token
|
2015-06-30 12:53:11 +02:00
|
|
|
return !string.IsNullOrEmpty(UploadToken);
|
2015-06-26 00:51:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-03 16:45:59 +01:00
|
|
|
private bool CheckCaseNumberValid(out string error)
|
|
|
|
{
|
|
|
|
error = string.Empty;
|
|
|
|
|
|
|
|
if (!uploadCheckBox.Checked || string.IsNullOrEmpty(caseNumberTextBox.Text.Trim()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ulong val;
|
|
|
|
if (ulong.TryParse(caseNumberTextBox.Text.Trim(), out val) && val > 0 && val < 1000000000)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error = Messages.BUGTOOL_PAGE_DESTINATION_INVALID_CASE_NO;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
#region Control event handlers
|
|
|
|
|
|
|
|
private void m_textBoxName_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2015-11-03 16:45:59 +01:00
|
|
|
PerformCheck(CheckPathValid, CheckCaseNumberValid, CheckCredentialsEntered);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void m_textBoxLocation_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2015-11-03 16:45:59 +01:00
|
|
|
PerformCheck(CheckPathValid, CheckCaseNumberValid, CheckCredentialsEntered);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void BrowseButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
2015-06-26 00:51:11 +02:00
|
|
|
using (FolderBrowserDialog dlog = new FolderBrowserDialog {SelectedPath = m_textBoxLocation.Text})
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
if (dlog.ShowDialog() == DialogResult.OK)
|
|
|
|
m_textBoxLocation.Text = dlog.SelectedPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:25:58 +01:00
|
|
|
private void uploadCheckBox_CheckedChanged(object sender, EventArgs e)
|
2015-06-26 00:51:11 +02:00
|
|
|
{
|
2015-11-03 16:45:59 +01:00
|
|
|
PerformCheck(CheckPathValid, CheckCaseNumberValid, CheckCredentialsEntered);
|
2015-06-26 00:51:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void credentials_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2015-11-10 13:25:58 +01:00
|
|
|
uploadCheckBox.Checked = true;
|
2015-11-03 16:45:59 +01:00
|
|
|
PerformCheck(CheckPathValid, CheckCaseNumberValid, CheckCredentialsEntered);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void caseNumberLabelTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2015-11-10 13:25:58 +01:00
|
|
|
uploadCheckBox.Checked = true;
|
2015-11-03 16:45:59 +01:00
|
|
|
PerformCheck(CheckPathValid, CheckCaseNumberValid, CheckCredentialsEntered);
|
2015-06-26 00:51:11 +02:00
|
|
|
}
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
#endregion
|
2016-01-19 16:35:01 +01:00
|
|
|
|
|
|
|
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
|
|
|
|
{
|
|
|
|
Program.OpenURL(e.LinkText);
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
}
|