2006-08-21 19:40:50 +02:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
2006-08-10 18:21:47 +02:00
|
|
|
using Novell.CASA.MiCasa.Communication;
|
2006-08-21 19:40:50 +02:00
|
|
|
using Novell.CASA.MiCasa.Common;
|
|
|
|
|
|
|
|
namespace Novell.CASA.GUI
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Summary description for ImportSecrets.
|
|
|
|
/// </summary>
|
|
|
|
public class ImportSecrets
|
|
|
|
{
|
|
|
|
Config m_config = null;
|
|
|
|
public MiCasa m_objMiCasa = null;
|
2006-08-22 18:45:08 +02:00
|
|
|
string sFile = null;
|
2006-08-21 19:40:50 +02:00
|
|
|
byte[] buffer = null;
|
2006-08-10 18:21:47 +02:00
|
|
|
|
|
|
|
[Glade.Widget]
|
|
|
|
Gtk.Entry entryMasterPassword;
|
|
|
|
|
|
|
|
[Glade.Widget]
|
2006-08-21 19:40:50 +02:00
|
|
|
Gtk.Dialog dialogImport,
|
|
|
|
dialogLogin;
|
|
|
|
|
|
|
|
public ImportSecrets(Config config, MiCasa objMiCasa)
|
|
|
|
{
|
|
|
|
m_config = config;
|
|
|
|
m_objMiCasa = objMiCasa;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Run()
|
|
|
|
{
|
|
|
|
String sHintDir = m_config.GetConfigSetting(CommonGUI.HINT_DIR, null);;
|
|
|
|
String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null);
|
2006-08-22 18:45:08 +02:00
|
|
|
|
2006-08-21 22:58:36 +02:00
|
|
|
FileChooser fc = new FileChooser(FileChooser.ACTION_OPEN);
|
2006-09-07 22:07:32 +02:00
|
|
|
sFile = fc.GetFile(sHintDir, sHintFilename, "*.casa");
|
2006-08-18 23:48:22 +02:00
|
|
|
|
2006-08-21 19:40:50 +02:00
|
|
|
//fc.Show(sHintDir, sHintFilename);
|
|
|
|
//sFile = fc.GetSelectedFile();
|
|
|
|
|
|
|
|
#if W32
|
|
|
|
// ask the user to locate the secret file to import
|
|
|
|
//sFile = CommonGUI.FileChooser(Gtk.FileChooserAction.Open, "Select import file", sHintDir, sHintFilename);
|
|
|
|
#else
|
|
|
|
//sFile = null;
|
|
|
|
//CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Not implemented");
|
|
|
|
#endif
|
|
|
|
if (sFile != null)
|
|
|
|
{
|
|
|
|
// parse of the file:///
|
|
|
|
if (sFile.StartsWith("file:///"))
|
|
|
|
{
|
|
|
|
sFile = sFile.Substring(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (File.Exists(sFile))
|
|
|
|
{
|
|
|
|
|
2006-09-22 22:29:12 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// let's read it
|
|
|
|
FileStream fs = new FileStream(sFile, FileMode.Open);
|
|
|
|
buffer = new byte[fs.Length];
|
2006-08-21 19:40:50 +02:00
|
|
|
|
2006-09-22 22:29:12 +02:00
|
|
|
int iBytes = fs.Read(buffer, 0, (int)fs.Length);
|
|
|
|
string data = System.Text.Encoding.ASCII.GetString(buffer);
|
2006-08-21 19:40:50 +02:00
|
|
|
|
2006-09-22 22:29:12 +02:00
|
|
|
fs.Flush();
|
|
|
|
fs.Close();
|
2006-08-21 19:40:50 +02:00
|
|
|
|
2006-09-22 22:29:12 +02:00
|
|
|
// check for clear text secrets
|
|
|
|
if (data.StartsWith("<?xml"))
|
|
|
|
{
|
|
|
|
ImportXMLSecrets addSecrets = new ImportXMLSecrets(null, null, sFile);
|
|
|
|
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_ADD_XML_SECRETS, null, null, null, addSecrets);
|
|
|
|
CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Import complete");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetMasterPasswordUsedForImport();
|
|
|
|
}
|
2006-08-21 19:40:50 +02:00
|
|
|
}
|
2006-09-22 22:29:12 +02:00
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
CommonGUI.DisplayMessage(Gtk.MessageType.Error, e.Message);
|
2006-08-21 19:40:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void GetMasterPasswordUsedForImport()
|
|
|
|
{
|
|
|
|
// prompt for master password, and optional passphrase to encrypt
|
2006-08-10 18:21:47 +02:00
|
|
|
//Logger.DbgLog("GUI:CasaMain.Login() - IsMasterPasswordSet returned false");
|
|
|
|
#if W32
|
|
|
|
Glade.XML gxmlTemp = new Glade.XML ("../images/casa.glade", "dialogImport", null);
|
|
|
|
#endif
|
|
|
|
#if LINUX
|
2006-08-22 18:56:56 +02:00
|
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogImport", null);
|
2006-08-10 18:21:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
gxmlTemp.Autoconnect (this);
|
|
|
|
dialogImport.TransientFor = (Gtk.Window)CasaMain.gxmlMain.GetWidget("windowMain");;
|
|
|
|
dialogImport.Modal = true;
|
2006-08-21 19:40:50 +02:00
|
|
|
dialogImport.Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnDialogLoginDeleted(object obj, EventArgs args)
|
2006-08-21 19:11:03 +02:00
|
|
|
{
|
|
|
|
//cbuttonShowPassword.Active = false;
|
|
|
|
dialogLogin.Destroy();
|
2006-08-21 19:40:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void okbuttonLogin_clicked(object obj, EventArgs args)
|
|
|
|
{
|
|
|
|
dialogLogin.Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void closebuttonLogin_clicked(object obj, EventArgs args)
|
|
|
|
{
|
|
|
|
dialogLogin.Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void on_entryMasterPassword3_activate(object obj, EventArgs args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void on_entryMasterPassword4_activate(object obj, EventArgs args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void on_helpbuttonAuthentication_clicked(object obj, EventArgs args)
|
|
|
|
{
|
|
|
|
Common.ShowHelpUrl("CASAMasterPasswordAuthentication.htm");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void on_buttonImportOK_clicked(object sender, EventArgs args)
|
|
|
|
{
|
|
|
|
if (entryMasterPassword != null)
|
|
|
|
{
|
2006-08-22 18:45:08 +02:00
|
|
|
ImportXMLSecrets addSecrets = new ImportXMLSecrets(entryMasterPassword.Text, null, sFile);
|
2006-08-21 19:40:50 +02:00
|
|
|
addSecrets = (ImportXMLSecrets)MiCasaRequestReply.Send(MiCasaRequestReply.VERB_ADD_XML_SECRETS, null, null, null, addSecrets);
|
|
|
|
|
2006-08-10 18:21:47 +02:00
|
|
|
if (dialogImport != null)
|
|
|
|
{
|
|
|
|
dialogImport.Destroy();
|
2006-08-21 19:40:50 +02:00
|
|
|
}
|
|
|
|
if (m_objMiCasa != null)
|
|
|
|
{
|
|
|
|
m_objMiCasa.AggregateStore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addSecrets.GetStatus().Equals("Success"))
|
|
|
|
CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Import complete");
|
|
|
|
else
|
|
|
|
CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Failed: " + addSecrets.GetStatus());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void on_buttonImportClose_clicked(object sender, EventArgs args)
|
|
|
|
{
|
2006-08-10 18:21:47 +02:00
|
|
|
if (dialogImport != null)
|
|
|
|
{
|
|
|
|
dialogImport.Destroy();
|
2006-08-21 19:40:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|