diff --git a/XenAdmin/Controls/CallHome/CallHomeAuthenticationPanel.cs b/XenAdmin/Controls/CallHome/CallHomeAuthenticationPanel.cs index 2ab913609..e8f7b7b06 100644 --- a/XenAdmin/Controls/CallHome/CallHomeAuthenticationPanel.cs +++ b/XenAdmin/Controls/CallHome/CallHomeAuthenticationPanel.cs @@ -76,7 +76,8 @@ namespace XenAdmin.Controls spinnerIcon.StartSpinning(); var action = new CallHomeAuthenticationAction(Pool, usernameTextBox.Text.Trim(), passwordTextBox.Text.Trim(), - Registry.CallHomeIdentityTokenDomainName, Registry.CallHomeUploadGrantTokenDomainName, Registry.CallHomeUploadTokenDomainName, false); + Registry.CallHomeIdentityTokenDomainName, Registry.CallHomeUploadGrantTokenDomainName, Registry.CallHomeUploadTokenDomainName, + true, 0, false); action.Completed += CallHomeAuthenticationAction_Completed; authenticateButton.Enabled = false; action.RunAsync(); diff --git a/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.Designer.cs b/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.Designer.cs index 1f520523b..dc56e908c 100644 --- a/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.Designer.cs +++ b/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.Designer.cs @@ -29,47 +29,94 @@ namespace XenAdmin.Wizards.BugToolWizardFiles private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BugToolPageDestination)); - this.labelFileLocation = new System.Windows.Forms.Label(); - this.BrowseButton = new System.Windows.Forms.Button(); - this.label2 = new System.Windows.Forms.Label(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.authenticationGroupBox = new System.Windows.Forms.GroupBox(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.autoHeightLabel2 = new XenAdmin.Controls.Common.AutoHeightLabel(); + this.usernameLabel = new System.Windows.Forms.Label(); + this.passwordLabel = new System.Windows.Forms.Label(); + this.passwordTextBox = new System.Windows.Forms.TextBox(); + this.usernameTextBox = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); this.labelName = new System.Windows.Forms.Label(); this.m_textBoxName = new System.Windows.Forms.TextBox(); + this.labelFileLocation = new System.Windows.Forms.Label(); this.m_textBoxLocation = new System.Windows.Forms.TextBox(); + this.BrowseButton = new System.Windows.Forms.Button(); this.m_ctrlError = new XenAdmin.Controls.Common.PasswordFailure(); + this.uploadCheckBox = new System.Windows.Forms.CheckBox(); this.tableLayoutPanel1.SuspendLayout(); + this.authenticationGroupBox.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); this.SuspendLayout(); // - // labelFileLocation - // - resources.ApplyResources(this.labelFileLocation, "labelFileLocation"); - this.labelFileLocation.Name = "labelFileLocation"; - // - // BrowseButton - // - resources.ApplyResources(this.BrowseButton, "BrowseButton"); - this.BrowseButton.Name = "BrowseButton"; - this.BrowseButton.UseVisualStyleBackColor = true; - this.BrowseButton.Click += new System.EventHandler(this.BrowseButton_Click); - // - // label2 - // - resources.ApplyResources(this.label2, "label2"); - this.tableLayoutPanel1.SetColumnSpan(this.label2, 3); - this.label2.Name = "label2"; - // // tableLayoutPanel1 // resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); + this.tableLayoutPanel1.Controls.Add(this.authenticationGroupBox, 0, 4); this.tableLayoutPanel1.Controls.Add(this.label2, 0, 0); this.tableLayoutPanel1.Controls.Add(this.labelName, 0, 1); this.tableLayoutPanel1.Controls.Add(this.m_textBoxName, 1, 1); this.tableLayoutPanel1.Controls.Add(this.labelFileLocation, 0, 2); this.tableLayoutPanel1.Controls.Add(this.m_textBoxLocation, 1, 2); this.tableLayoutPanel1.Controls.Add(this.BrowseButton, 2, 2); - this.tableLayoutPanel1.Controls.Add(this.m_ctrlError, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.m_ctrlError, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.uploadCheckBox, 0, 3); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; // + // authenticationGroupBox + // + resources.ApplyResources(this.authenticationGroupBox, "authenticationGroupBox"); + this.tableLayoutPanel1.SetColumnSpan(this.authenticationGroupBox, 3); + this.authenticationGroupBox.Controls.Add(this.tableLayoutPanel2); + this.authenticationGroupBox.Name = "authenticationGroupBox"; + this.authenticationGroupBox.TabStop = false; + // + // tableLayoutPanel2 + // + resources.ApplyResources(this.tableLayoutPanel2, "tableLayoutPanel2"); + this.tableLayoutPanel2.Controls.Add(this.autoHeightLabel2, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.usernameLabel, 0, 1); + this.tableLayoutPanel2.Controls.Add(this.passwordLabel, 0, 2); + this.tableLayoutPanel2.Controls.Add(this.passwordTextBox, 1, 2); + this.tableLayoutPanel2.Controls.Add(this.usernameTextBox, 1, 1); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + // + // autoHeightLabel2 + // + resources.ApplyResources(this.autoHeightLabel2, "autoHeightLabel2"); + this.tableLayoutPanel2.SetColumnSpan(this.autoHeightLabel2, 3); + this.autoHeightLabel2.Name = "autoHeightLabel2"; + // + // usernameLabel + // + resources.ApplyResources(this.usernameLabel, "usernameLabel"); + this.usernameLabel.Name = "usernameLabel"; + // + // passwordLabel + // + resources.ApplyResources(this.passwordLabel, "passwordLabel"); + this.passwordLabel.Name = "passwordLabel"; + // + // passwordTextBox + // + resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); + this.passwordTextBox.Name = "passwordTextBox"; + this.passwordTextBox.UseSystemPasswordChar = true; + this.passwordTextBox.TextChanged += new System.EventHandler(this.credentials_TextChanged); + // + // usernameTextBox + // + resources.ApplyResources(this.usernameTextBox, "usernameTextBox"); + this.usernameTextBox.Name = "usernameTextBox"; + this.usernameTextBox.TextChanged += new System.EventHandler(this.credentials_TextChanged); + // + // label2 + // + resources.ApplyResources(this.label2, "label2"); + this.tableLayoutPanel1.SetColumnSpan(this.label2, 3); + this.label2.Name = "label2"; + // // labelName // resources.ApplyResources(this.labelName, "labelName"); @@ -81,17 +128,38 @@ namespace XenAdmin.Wizards.BugToolWizardFiles this.m_textBoxName.Name = "m_textBoxName"; this.m_textBoxName.TextChanged += new System.EventHandler(this.m_textBoxName_TextChanged); // + // labelFileLocation + // + resources.ApplyResources(this.labelFileLocation, "labelFileLocation"); + this.labelFileLocation.Name = "labelFileLocation"; + // // m_textBoxLocation // resources.ApplyResources(this.m_textBoxLocation, "m_textBoxLocation"); this.m_textBoxLocation.Name = "m_textBoxLocation"; this.m_textBoxLocation.TextChanged += new System.EventHandler(this.m_textBoxLocation_TextChanged); // + // BrowseButton + // + resources.ApplyResources(this.BrowseButton, "BrowseButton"); + this.BrowseButton.Name = "BrowseButton"; + this.BrowseButton.UseVisualStyleBackColor = true; + this.BrowseButton.Click += new System.EventHandler(this.BrowseButton_Click); + // // m_ctrlError // resources.ApplyResources(this.m_ctrlError, "m_ctrlError"); + this.tableLayoutPanel1.SetColumnSpan(this.m_ctrlError, 3); this.m_ctrlError.Name = "m_ctrlError"; // + // uploadCheckBox + // + resources.ApplyResources(this.uploadCheckBox, "uploadCheckBox"); + this.tableLayoutPanel1.SetColumnSpan(this.uploadCheckBox, 3); + this.uploadCheckBox.Name = "uploadCheckBox"; + this.uploadCheckBox.UseVisualStyleBackColor = true; + this.uploadCheckBox.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); + // // BugToolPageDestination // this.Controls.Add(this.tableLayoutPanel1); @@ -100,19 +168,31 @@ namespace XenAdmin.Wizards.BugToolWizardFiles resources.ApplyResources(this, "$this"); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); + this.authenticationGroupBox.ResumeLayout(false); + this.authenticationGroupBox.PerformLayout(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); this.ResumeLayout(false); } #endregion - private System.Windows.Forms.Label labelFileLocation; - private System.Windows.Forms.Button BrowseButton; private System.Windows.Forms.Label label2; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Label labelName; private System.Windows.Forms.TextBox m_textBoxName; - private System.Windows.Forms.TextBox m_textBoxLocation; private XenAdmin.Controls.Common.PasswordFailure m_ctrlError; + private System.Windows.Forms.CheckBox uploadCheckBox; + private System.Windows.Forms.GroupBox authenticationGroupBox; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.Label usernameLabel; + private System.Windows.Forms.Label passwordLabel; + private System.Windows.Forms.TextBox passwordTextBox; + private System.Windows.Forms.TextBox usernameTextBox; + private Controls.Common.AutoHeightLabel autoHeightLabel2; + private System.Windows.Forms.Label labelFileLocation; + private System.Windows.Forms.TextBox m_textBoxLocation; + private System.Windows.Forms.Button BrowseButton; } } diff --git a/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.cs b/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.cs index c691a5421..0eaaef877 100644 --- a/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.cs +++ b/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.cs @@ -38,9 +38,11 @@ using System.IO; using System.Text; using System.Windows.Forms; using Microsoft.Win32; +using XenAdmin.Actions; using XenAdmin.Controls; using XenAdmin.Controls.Common; using XenAdmin.Core; +using Registry = XenAdmin.Core.Registry; namespace XenAdmin.Wizards.BugToolWizardFiles @@ -48,6 +50,8 @@ namespace XenAdmin.Wizards.BugToolWizardFiles public partial class BugToolPageDestination : XenTabPage { private bool m_buttonNextEnabled; + + private const int TokenExpiration = 86400; // 24 hours public BugToolPageDestination() { @@ -82,13 +86,14 @@ namespace XenAdmin.Wizards.BugToolWizardFiles public override void PageLoaded(PageLoadedDirection direction) { base.PageLoaded(direction); - PerformCheck(CheckPathValid); + EnableDisableAuthenticationControls(); + PerformCheck(CheckPathValid, CheckCredentialsEntered); } public override void PageLeave(PageLoadedDirection direction, ref bool cancel) { if (direction == PageLoadedDirection.Forward) - cancel = !PerformCheck(CheckPathValid); + cancel = !PerformCheck(CheckPathValid, CheckCredentialsEntered, CheckUploadAuthentication); base.PageLeave(direction, ref cancel); } @@ -106,6 +111,16 @@ namespace XenAdmin.Wizards.BugToolWizardFiles } } + public bool Upload + { + get + { + return uploadCheckBox.Enabled; + } + } + + public string UploadToken { get; private set; } + private bool PerformCheck(params CheckDelegate[] checks) { bool success = m_ctrlError.PerformCheck(checks); @@ -144,27 +159,88 @@ namespace XenAdmin.Wizards.BugToolWizardFiles return true; } + private bool CheckCredentialsEntered(out string error) + { + error = string.Empty; + + if (!uploadCheckBox.Checked) + return true; + + if (string.IsNullOrEmpty(usernameTextBox.Text) || string.IsNullOrEmpty(passwordTextBox.Text)) + return false; + + return true; + } + + private bool CheckUploadAuthentication(out string error) + { + error = string.Empty; + + if (!uploadCheckBox.Checked) + return true; + + if (string.IsNullOrEmpty(usernameTextBox.Text) || string.IsNullOrEmpty(passwordTextBox.Text)) + return false; + + var action = new CallHomeAuthenticationAction(null, usernameTextBox.Text.Trim(), passwordTextBox.Text.Trim(), + Registry.CallHomeIdentityTokenDomainName, Registry.CallHomeUploadGrantTokenDomainName, Registry.CallHomeUploadTokenDomainName, + false, TokenExpiration, false); + + try + { + action.RunExternal(null); + } + catch + { + error = action.Exception != null ? action.Exception.Message : Messages.ERROR_UNKNOWN; + UploadToken = null; + return false; + } + + UploadToken = action.UploadToken; // curent upload token + return !string.IsNullOrEmpty(UploadToken); + } + + private void EnableDisableAuthenticationControls() + { + if (!Visible) + return; + + authenticationGroupBox.Enabled = uploadCheckBox.Checked; + } + #region Control event handlers private void m_textBoxName_TextChanged(object sender, EventArgs e) { - PerformCheck(CheckPathValid); + PerformCheck(CheckPathValid, CheckCredentialsEntered); } private void m_textBoxLocation_TextChanged(object sender, EventArgs e) { - PerformCheck(CheckPathValid); + PerformCheck(CheckPathValid, CheckCredentialsEntered); } private void BrowseButton_Click(object sender, EventArgs e) { - using (FolderBrowserDialog dlog = new FolderBrowserDialog { SelectedPath = m_textBoxLocation.Text }) + using (FolderBrowserDialog dlog = new FolderBrowserDialog {SelectedPath = m_textBoxLocation.Text}) { if (dlog.ShowDialog() == DialogResult.OK) m_textBoxLocation.Text = dlog.SelectedPath; } } + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + EnableDisableAuthenticationControls(); + PerformCheck(CheckPathValid, CheckCredentialsEntered); + } + + private void credentials_TextChanged(object sender, EventArgs e) + { + PerformCheck(CheckPathValid, CheckCredentialsEntered); + } + #endregion } } diff --git a/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.resx b/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.resx index 4ab30f17c..f2bd74014 100644 --- a/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.resx +++ b/XenAdmin/Wizards/BugToolWizardFiles/BugToolPageDestination.resx @@ -112,25 +112,361 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + 3 + + + True + + + True + + + 2 + + + True + + + + Fill + + + NoControl + + + + 3, 3 + + + 3, 3, 3, 6 + + + 548, 26 + + + 11 + + + Enter your MyCitrix credentials. These credentials will only be used to authenticate with the Citrix upload server once and will not be stored on this machine or on your server. + + + autoHeightLabel2 + + + XenAdmin.Controls.Common.AutoHeightLabel, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + tableLayoutPanel2 + + + 0 + + + True + + + Fill + + + Segoe UI, 9pt + + + NoControl + + + 0, 35 + + + 0, 0, 0, 0 + + + 66, 29 + + + 12 + + + U&ser name: + + + MiddleLeft + + + usernameLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 1 + + + True + + + Fill + + + Segoe UI, 9pt + + + NoControl + + + 0, 64 + + + 0, 0, 0, 0 + + + 66, 29 + + + 14 + + + P&assword: + + + MiddleLeft + + + passwordLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 2 + + + Segoe UI, 9pt + + + 69, 67 + + + 246, 23 + + + 15 + + + passwordTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 3 + + + Segoe UI, 9pt + + + 69, 38 + + + 246, 23 + + + 13 + + + usernameTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 4 + + + Fill + + + 6, 19 + + + 4 + + + 554, 93 + + + 1 + + + tableLayoutPanel2 + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + authenticationGroupBox + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="autoHeightLabel2" Row="0" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="usernameLabel" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="passwordLabel" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="passwordTextBox" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="usernameTextBox" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,20,AutoSize,100,AutoSize,0,AutoSize,20,Absolute,20" /></TableLayoutSettings> + + + Top + + + 3, 125 + + + 6, 6, 3, 3 + + + 563, 115 + + + 9 + + + Authentication with Citrix upload server + + + authenticationGroupBox + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 0 + + + True + + + Fill + + + NoControl + + + 3, 0 + + + 0, 0, 0, 12 + + + 563, 25 + + + 0 + + + You are now ready to save your status report. Use the browse button to select a location to save your report. + + + label2 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 1 + + + Left + + + True + + + NoControl + + + 3, 31 + + + 3, 3, 3, 3 + + + 55, 13 + + + 1 + + + File na&me: + + + labelName + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 2 + + + Fill + + + 75, 28 + + + 410, 20 + + + 2 + + + m_textBoxName + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 3 + Left - True NoControl - - 3, 91 + 3, 66 3, 10, 3, 3 @@ -151,19 +487,46 @@ labelFileLocation - System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 tableLayoutPanel1 - 3 + 4 + + + Fill + + + 75, 61 + + + 3, 10, 3, 3 + + + 410, 20 + + + 4 + + + m_textBoxLocation + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 5 NoControl - 491, 86 + 491, 61 3, 10, 3, 3 @@ -181,103 +544,13 @@ BrowseButton - System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 tableLayoutPanel1 - 5 - - - True - - - 3 - - - Left - - - True - - - 3, 56 - - - 3, 3, 3, 3 - - - 55, 13 - - - 1 - - - File na&me: - - - labelName - - - System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 1 - - - Fill - - - 75, 53 - - - 410, 20 - - - 2 - - - m_textBoxName - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 2 - - - Fill - - - 75, 86 - - - 3, 10, 3, 3 - - - 410, 20 - - - 4 - - - m_textBoxLocation - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 4 + 6 True @@ -292,16 +565,16 @@ - 72, 112 + 0, 243 0, 0, 0, 0 - 416, 22 + 569, 22 - 6 + 10 m_ctrlError @@ -313,7 +586,40 @@ tableLayoutPanel1 - 6 + 7 + + + True + + + NoControl + + + 3, 99 + + + 3, 12, 3, 6 + + + 228, 17 + + + 8 + + + &Upload the status report to the CIS website + + + uploadCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 8 Fill @@ -325,7 +631,7 @@ 0, 0, 0, 0 - 5 + 7 569, 419 @@ -337,7 +643,7 @@ tableLayoutPanel1 - System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 $this @@ -346,42 +652,9 @@ 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="label2" Row="0" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="labelName" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="m_textBoxName" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="labelFileLocation" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="m_textBoxLocation" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="BrowseButton" Row="2" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="m_ctrlError" Row="3" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100,AutoSize,0" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="authenticationGroupBox" Row="4" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="label2" Row="0" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="labelName" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="m_textBoxName" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="labelFileLocation" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="m_textBoxLocation" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="BrowseButton" Row="2" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="m_ctrlError" Row="5" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="uploadCheckBox" Row="3" RowSpan="1" Column="0" ColumnSpan="3" /></Controls><Columns Styles="AutoSize,0,Percent,100,AutoSize,0" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100" /></TableLayoutSettings> - - Fill - - - NoControl - - - 3, 0 - - - 0, 0, 0, 24 - - - 563, 50 - - - 0 - - - You are now ready to save your status report. Use the browse button to select a location to save your report to and click the finish button to exit the wizard. - - - label2 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 0 - - + True diff --git a/XenModel/Actions/CallHome/CallHomeAuthenticationAction.cs b/XenModel/Actions/CallHome/CallHomeAuthenticationAction.cs index 99076c63e..82611c220 100644 --- a/XenModel/Actions/CallHome/CallHomeAuthenticationAction.cs +++ b/XenModel/Actions/CallHome/CallHomeAuthenticationAction.cs @@ -9,32 +9,47 @@ using System.Web.Script.Serialization; namespace XenAdmin.Actions { - public class CallHomeAuthenticationAction : PureAsyncAction + public class CallHomeAuthenticationAction : AsyncAction { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private readonly Pool pool; private readonly string username; - private string password; - private readonly string identityTokenUrl = "/auth/api/create_identity/"; - private readonly string uploadGrantTokenUrl = "/feeds/api/create_grant/"; - private readonly string uploadTokenUrl = "/feeds/api/create_upload/"; + private readonly string password; + + private readonly bool saveTokenAsSecret; + private readonly long tokenExpiration; + + private string uploadToken; + + private const string identityTokenUrl = "/auth/api/create_identity/"; + private const string uploadGrantTokenUrl = "/feeds/api/create_grant/"; + private const string uploadTokenUrl = "/feeds/api/create_upload/"; + private readonly string identityTokenDomainName = "http://cis-daily.citrite.net"; private readonly string uploadGrantTokenDomainName = "https://rttf-staging.citrix.com"; private readonly string uploadTokenDomainName = "https://rttf-staging.citrix.com"; + private const string productKey = "eb1b224c461038baf1f08dfba6b8d4b4413f96c7"; - public CallHomeAuthenticationAction(Pool pool, string username, string password, bool suppressHistory) - : base(pool.Connection, Messages.ACTION_CALLHOME_AUTHENTICATION, Messages.ACTION_CALLHOME_AUTHENTICATION_PROGRESS, suppressHistory) + public CallHomeAuthenticationAction(Pool pool, string username, string password, bool saveTokenAsSecret, long tokenExpiration, bool suppressHistory) + : base(pool != null ? pool.Connection : null, Messages.ACTION_CALLHOME_AUTHENTICATION, Messages.ACTION_CALLHOME_AUTHENTICATION_PROGRESS, suppressHistory) { this.pool = pool; this.username = username; this.password = password; + this.saveTokenAsSecret = saveTokenAsSecret; + this.tokenExpiration = tokenExpiration; + #region RBAC Dependencies + if (saveTokenAsSecret) + ApiMethodsToRoleCheck.Add("pool.set_health_check_config"); + #endregion + } - public CallHomeAuthenticationAction(Pool pool, string username, string password, - string identityTokenDomainName, string uploadGrantTokenDomainName, string uploadTokenDomainName, bool suppressHistory) - : this(pool, username, password, suppressHistory) + public CallHomeAuthenticationAction(Pool pool, string username, string password, + string identityTokenDomainName, string uploadGrantTokenDomainName, string uploadTokenDomainName, bool saveTokenAsSecret, long tokenExpiration, bool suppressHistory) + : this(pool, username, password, saveTokenAsSecret, tokenExpiration, suppressHistory) { if (!string.IsNullOrEmpty(identityTokenDomainName)) this.identityTokenDomainName = identityTokenDomainName; @@ -46,15 +61,20 @@ namespace XenAdmin.Actions protected override void Run() { - Dictionary newConfig = pool.gui_config; + System.Diagnostics.Trace.Assert(pool != null || !saveTokenAsSecret, "Pool is null! Cannot save token as secret"); try { string identityToken = GetIdentityToken(); string uploadGrantToken = GetUploadGrantToken(identityToken); - string uploadToken = GetUploadToken(uploadGrantToken); + uploadToken = GetUploadToken(uploadGrantToken); - SetUploadTokenSecret(Connection, newConfig, uploadToken); - Pool.set_gui_config(Connection.Session, pool.opaque_ref, newConfig); + if (saveTokenAsSecret && pool != null) + { + log.Info("Saving upload token as xapi secret"); + Dictionary newConfig = pool.health_check_config; + SetTokenSecret(Connection, newConfig, CallHomeSettings.UPLOAD_TOKEN_SECRET, uploadToken); + Pool.set_health_check_config(Connection.Session, pool.opaque_ref, newConfig); + } } catch (Exception e) { @@ -63,31 +83,41 @@ namespace XenAdmin.Actions } } + public string UploadToken + { + get { return uploadToken; } + } + public static void SetUploadTokenSecret(IXenConnection connection, Dictionary config, string uploadToken) { - if (uploadToken == null) + SetTokenSecret(connection, config, CallHomeSettings.UPLOAD_TOKEN_SECRET, uploadToken); + } + + public static void SetTokenSecret(IXenConnection connection, Dictionary config, string tokenKey, string tokenValue) + { + if (tokenValue == null) { - config.Remove(CallHomeSettings.UPLOAD_TOKEN_SECRET); + config.Remove(tokenKey); } - else if (config.ContainsKey(CallHomeSettings.UPLOAD_TOKEN_SECRET)) + else if (config.ContainsKey(tokenKey)) { try { - string secretRef = Secret.get_by_uuid(connection.Session, config[CallHomeSettings.UPLOAD_TOKEN_SECRET]); - Secret.set_value(connection.Session, secretRef, uploadToken); + string secretRef = Secret.get_by_uuid(connection.Session, config[tokenKey]); + Secret.set_value(connection.Session, secretRef, tokenValue); } catch (Failure) { - config[CallHomeSettings.UPLOAD_TOKEN_SECRET] = Secret.CreateSecret(connection.Session, uploadToken); + config[tokenKey] = Secret.CreateSecret(connection.Session, tokenValue); } catch (WebException) { - config[CallHomeSettings.UPLOAD_TOKEN_SECRET] = Secret.CreateSecret(connection.Session, uploadToken); + config[tokenKey] = Secret.CreateSecret(connection.Session, tokenValue); } } else { - config[CallHomeSettings.UPLOAD_TOKEN_SECRET] = Secret.CreateSecret(connection.Session, uploadToken); + config[tokenKey] = Secret.CreateSecret(connection.Session, tokenValue); } } @@ -106,7 +136,8 @@ namespace XenAdmin.Actions { var json = new JavaScriptSerializer().Serialize(new { - identity_token = identityToken + identity_token = identityToken, + expiration = tokenExpiration }); var urlString = string.Format("{0}{1}", uploadGrantTokenDomainName, uploadGrantTokenUrl); return GetToken(urlString, json); @@ -117,7 +148,8 @@ namespace XenAdmin.Actions var json = new JavaScriptSerializer().Serialize(new { grant_token = grantToken, - product_key = productKey + product_key = productKey, + expiration = tokenExpiration }); var urlString = string.Format("{0}{1}", uploadTokenDomainName, uploadTokenUrl); return GetToken(urlString, json);