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.Actions ;
using XenAdmin.Core ;
using XenAdmin.Dialogs.RestoreSession ;
namespace XenAdmin.Dialogs.OptionsPages
{
/// <summary>
2021-08-31 12:31:16 +02:00
/// The page is used to set whether or not to save server usernames and passwords and whether a coordinator password should be set to protect these passwords
2013-06-24 13:41:48 +02:00
/// </summary>
public partial class SaveAndRestoreOptionsPage : UserControl , IOptionsPage
{
2021-08-31 12:31:16 +02:00
private byte [ ] TemporaryMainPassword ;
2013-06-24 13:41:48 +02:00
// call save serverlist on OK
protected internal bool SaveAllAfter { get ; set ; }
public SaveAndRestoreOptionsPage ( )
{
InitializeComponent ( ) ;
2021-03-16 02:50:45 +01:00
saveStateLabel . Text = string . Format ( saveStateLabel . Text , BrandManager . BrandConsole ) ;
2013-06-24 13:41:48 +02:00
}
// all prompts for old password should have been made
private void SaveEverything ( )
{
if ( ! Registry . AllowCredentialSave )
{
return ;
}
if ( ! saveStateCheckBox . Checked )
{
// save nothing and nobody (personally my two favourite servers anyway...)
Properties . Settings . Default . SaveSession = false ;
Properties . Settings . Default . RequirePass = false ;
2021-08-31 12:31:16 +02:00
Program . MainPassword = null ;
2013-06-24 13:41:48 +02:00
}
2021-08-31 12:31:16 +02:00
else if ( ! requireMainPasswordCheckBox . Checked )
2013-06-24 13:41:48 +02:00
{
// we need to save stuff but without a password
Properties . Settings . Default . SaveSession = true ;
Properties . Settings . Default . RequirePass = false ;
2021-08-31 12:31:16 +02:00
Program . MainPassword = null ;
2013-06-24 13:41:48 +02:00
}
else
{
// password protect stuff
Properties . Settings . Default . SaveSession = true ;
Properties . Settings . Default . RequirePass = true ;
// set password
2021-08-31 12:31:16 +02:00
if ( Program . MainPassword ! = TemporaryMainPassword )
2016-11-10 12:12:01 +01:00
{
2021-08-31 12:31:16 +02:00
Program . MainPassword = TemporaryMainPassword ;
new ActionBase ( string . Format ( Messages . CHANGED_MAIN_PASSWORD , BrandManager . BrandConsole ) ,
string . Format ( Messages . CHANGED_MAIN_PASSWORD_LONG , BrandManager . BrandConsole ) ,
2021-03-16 02:50:45 +01:00
false , true ) ;
2016-11-10 12:12:01 +01:00
}
2013-06-24 13:41:48 +02:00
}
if ( SaveAllAfter )
Settings . SaveServerList ( ) ;
}
#region Control event handlers
2021-08-31 12:31:16 +02:00
private void changeMainPasswordButton_Click ( object sender , EventArgs e )
2013-06-24 13:41:48 +02:00
{
// tell the dialog what to use as the "current" password
2021-08-31 12:31:16 +02:00
using ( var changePassword = new ChangeMainPasswordDialog ( TemporaryMainPassword ) )
2013-06-24 13:41:48 +02:00
{
if ( changePassword . ShowDialog ( this ) = = DialogResult . OK )
{
// password has been successfully changed
2021-08-31 12:31:16 +02:00
TemporaryMainPassword = changePassword . NewPassword ;
2013-06-24 13:41:48 +02:00
}
}
}
2021-08-31 12:31:16 +02:00
private void requireMainPasswordCheckBox_Click ( object sender , EventArgs e )
2013-06-24 13:41:48 +02:00
{
2021-08-31 12:31:16 +02:00
// requireCoordinatorPasswordCheckBox.Checked was the state before the click
2013-06-24 13:41:48 +02:00
// if previously checked, the user is trying to clear it => request authorization
// if previously unchecked, the user is trying to set a password
2021-08-31 12:31:16 +02:00
if ( requireMainPasswordCheckBox . Checked )
2013-06-24 13:41:48 +02:00
{
2021-08-31 12:31:16 +02:00
using ( var enterPassword = new EnterMainPasswordDialog ( TemporaryMainPassword ) )
2013-06-24 13:41:48 +02:00
{
if ( enterPassword . ShowDialog ( this ) = = DialogResult . OK )
{
2021-08-31 12:31:16 +02:00
TemporaryMainPassword = null ;
requireMainPasswordCheckBox . Checked = false ;
changeMainPasswordButton . Enabled = false ;
2013-06-24 13:41:48 +02:00
}
}
}
else
{
2021-08-31 12:31:16 +02:00
System . Diagnostics . Debug . Assert ( TemporaryMainPassword = = null , "Main password is set, but not reflected on GUI" ) ;
2013-06-24 13:41:48 +02:00
2021-08-31 12:31:16 +02:00
if ( TemporaryMainPassword = = null )
2013-06-24 13:41:48 +02:00
{
// no previous password existed => set a new one
2021-08-31 12:31:16 +02:00
using ( var setPassword = new SetMainPasswordDialog ( ) )
2013-06-24 13:41:48 +02:00
{
if ( setPassword . ShowDialog ( this ) = = DialogResult . OK )
{
2021-08-31 12:31:16 +02:00
TemporaryMainPassword = setPassword . NewPassword ;
requireMainPasswordCheckBox . Checked = true ;
changeMainPasswordButton . Enabled = true ;
2013-06-24 13:41:48 +02:00
}
}
}
else
{
// a previous password existed (should never get here but just in case)
// enable button to facilitate password change
2021-08-31 12:31:16 +02:00
requireMainPasswordCheckBox . Checked = true ;
changeMainPasswordButton . Enabled = true ;
2013-06-24 13:41:48 +02:00
}
}
}
private void saveStateCheckBox_Click ( object sender , EventArgs e )
{
// need to prevent the user from going to an open terminal and clearing
2021-08-31 12:31:16 +02:00
// the save state, then setting the coordinator password to anything they like
2013-06-24 13:41:48 +02:00
// saveStateCheckBox.Checked was the state before the click
// if previously checked, the user is trying to clear it => authorization maybe required
2021-08-31 12:31:16 +02:00
// (depending on the state of the requireCoordinatorPasswordCheckBox; this should be cleared too if checked)
2013-06-24 13:41:48 +02:00
2021-08-31 12:31:16 +02:00
if ( saveStateCheckBox . Checked & & requireMainPasswordCheckBox . Checked )
2013-06-24 13:41:48 +02:00
{
2021-08-31 12:31:16 +02:00
using ( var enterPassword = new EnterMainPasswordDialog ( TemporaryMainPassword ) )
2013-06-24 13:41:48 +02:00
{
if ( enterPassword . ShowDialog ( this ) = = DialogResult . OK )
{
2021-08-31 12:31:16 +02:00
TemporaryMainPassword = null ;
2013-06-24 13:41:48 +02:00
saveStateCheckBox . Checked = false ;
2021-08-31 12:31:16 +02:00
requireMainPasswordCheckBox . Checked = false ;
mainPasswordGroupBox . Enabled = false ;
2013-06-24 13:41:48 +02:00
}
}
}
else
{
saveStateCheckBox . Checked = ! saveStateCheckBox . Checked ;
2021-08-31 12:31:16 +02:00
mainPasswordGroupBox . Enabled = saveStateCheckBox . Checked ;
changeMainPasswordButton . Enabled = requireMainPasswordCheckBox . Checked ;
2013-06-24 13:41:48 +02:00
}
}
#endregion
2020-10-22 03:07:02 +02:00
#region IOptionsPage Members
public void Build ( )
2013-06-24 13:41:48 +02:00
{
bool allowCredSave = Registry . AllowCredentialSave ;
bool saveSession = Properties . Settings . Default . SaveSession ;
bool reqPass = Properties . Settings . Default . RequirePass ;
saveStateLabel . Enabled = allowCredSave ;
saveStateCheckBox . Enabled = allowCredSave ;
// use the SaveSession variable to denote whether to save passwords or not
saveStateCheckBox . Checked = saveSession & & allowCredSave ;
2021-08-31 12:31:16 +02:00
mainPasswordGroupBox . Enabled = saveSession & & allowCredSave ;
2013-06-24 13:41:48 +02:00
2021-08-31 12:31:16 +02:00
// use the RequirePass variable to say if a main password has been set
requireMainPasswordCheckBox . Checked = reqPass & & Program . MainPassword ! = null & & allowCredSave ;
changeMainPasswordButton . Enabled = reqPass & & Program . MainPassword ! = null & & allowCredSave ;
2013-06-24 13:41:48 +02:00
2021-08-31 12:31:16 +02:00
// the temporary password starts as the MainPassword
TemporaryMainPassword = Program . MainPassword ;
2013-06-24 13:41:48 +02:00
}
2020-10-22 03:07:02 +02:00
public bool IsValidToSave ( )
{
return true ;
}
2013-06-24 13:41:48 +02:00
2020-10-22 03:07:02 +02:00
public void ShowValidationMessages ( )
{
}
2021-08-23 11:34:46 +02:00
public void HideValidationMessages ( )
{
}
2013-06-24 13:41:48 +02:00
public void Save ( )
{
SaveEverything ( ) ;
}
#endregion
2018-03-20 18:02:45 +01:00
#region IVerticalTab Members
2013-06-24 13:41:48 +02:00
2020-06-19 18:31:01 +02:00
public override string Text = > Messages . SAVE_AND_RESTORE ;
2013-06-24 13:41:48 +02:00
2020-06-19 18:31:01 +02:00
public string SubText = > Messages . SAVE_AND_RESTORE_DESC ;
2013-06-24 13:41:48 +02:00
2020-06-18 02:20:29 +02:00
public Image Image = > Images . StaticImages . _000_BackupMetadata_h32bit_16 ;
2013-06-24 13:41:48 +02:00
#endregion
}
}