2005-10-11 21:51:00 +02:00
|
|
|
///#################################################################
|
|
|
|
/// PROJECT : CASA - Common Authentication Services Adapter
|
|
|
|
/// FILE : Common.cs
|
|
|
|
/// DESCRIPTION : Class for defining constants and common static
|
|
|
|
/// methods.
|
|
|
|
/// AUTHORS : CSL.Manojna
|
|
|
|
/// UPDATED ON : 24 Sept, 05
|
|
|
|
///#################################################################
|
|
|
|
|
|
|
|
|
|
|
|
namespace Novell.CASA.GUI {
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Text;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
using Gtk;
|
|
|
|
using Glade;
|
|
|
|
|
|
|
|
|
|
|
|
public class Common
|
|
|
|
{
|
|
|
|
|
|
|
|
public const int STORE_MICASA = 0,
|
|
|
|
STORE_FIREFOX = 1,
|
|
|
|
STORE_MOZILLA = 2,
|
|
|
|
STORE_KDEWALLET = 3,
|
|
|
|
STORE_GNOMEKEYRING = 4;
|
|
|
|
|
|
|
|
public static bool IS_MICASA = true,
|
|
|
|
IS_FIREFOX = false,
|
|
|
|
IS_MOZILLA = false,
|
|
|
|
IS_KDEWALLET = false,
|
|
|
|
IS_GNOMEKEYRING = false;
|
|
|
|
|
|
|
|
public static bool IS_LINUX = false,
|
|
|
|
IS_WINDOWS = false;
|
|
|
|
|
|
|
|
public static string GladeFile = null,
|
|
|
|
DebugLogFile = null;
|
|
|
|
|
|
|
|
|
|
|
|
///##############################################################
|
|
|
|
/// SPI CONSTANTS
|
|
|
|
///
|
|
|
|
|
|
|
|
public static int MAX_STORES = 10;
|
|
|
|
|
|
|
|
public static string STORENAME_MICASA = "miCASA",
|
|
|
|
STORENAME_FIREFOX = "Firefox",
|
|
|
|
STORENAME_MOZILLA = "Mozilla",
|
|
|
|
STORENAME_KDEWALLET = "KDE KWallet",
|
|
|
|
STORENAME_GNOMEKEYRING = "GNOME Keyring";
|
|
|
|
|
|
|
|
|
|
|
|
///##############################################################
|
|
|
|
/// SDI CONSTANTS
|
|
|
|
///
|
|
|
|
|
|
|
|
//Operations
|
|
|
|
public static int OPERATION_ADD_SECRET = 0,
|
|
|
|
OPERATION_ADD_KEY = 1,
|
|
|
|
OPERATION_MODIFY_KEY = 2,
|
|
|
|
OPERATION_DELETE_SECRET = 3,
|
|
|
|
OPERATION_DELETE_KEY = 4;
|
|
|
|
|
|
|
|
//Limits
|
|
|
|
public static int MAX_ARRAY_ELEMENTS = 10;
|
|
|
|
public static int MAX_NATIVE_ELEMENTS = 5;
|
|
|
|
|
|
|
|
public static string NATIVEINFO_FOLDERNAME = "Folder Name";
|
|
|
|
public static string NATIVEINFO_TYPEID = "Type of Secret";
|
|
|
|
public static string NATIVEINFO_SYNC = "Syncronization Status";
|
|
|
|
public static string NATIVEINFO_SYNCTYPE = "Syncronization Type";
|
|
|
|
public static string NATIVEINFO_MODIFIEDTIME = "Last Modified Time";
|
|
|
|
|
|
|
|
public static int INDEX_NATIVEINFO_FOLDERNAME = 0,
|
|
|
|
INDEX_NATIVEINFO_TYPEID = 1,
|
|
|
|
INDEX_NATIVEINFO_SYNC = 2,
|
|
|
|
INDEX_NATIVEINFO_SYNCTYPE = 3,
|
|
|
|
INDEX_NATIVEINFO_MODIFIEDTIME = 4;
|
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
///##############################################################
|
|
|
|
/// ARG CONSTANTS
|
|
|
|
public static string ARG_SHOW_TRAY_ICON = "tray";
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
///##############################################################
|
|
|
|
/// ERROR CODES
|
|
|
|
|
|
|
|
public static int STATUS_SUCCESS = 0,
|
|
|
|
STATUS_FAILURE = 1,
|
|
|
|
|
|
|
|
// POLICY STATUS CODE RANGE: 2 - 20
|
|
|
|
STATUS_POLICY_COULDNOTBESAVED = 2,
|
|
|
|
STATUS_POLICY_POLICYNOTFOUND = 3,
|
|
|
|
|
|
|
|
// STORE STATUS CODE RANGE: 21 - 40
|
|
|
|
STATUS_STORE_INVALIDSTOREID = 21,
|
|
|
|
STATUS_STORE_DATANOTFOUNDINSTORE = 22,
|
|
|
|
STATUS_STORE_UNSUPPORTEDOPERATION = 23,
|
|
|
|
STATUS_STORE_ADINITFAILED = 24,
|
|
|
|
STATUS_STORE_AGGREGATEFAILED = 25,
|
|
|
|
STATUS_STORE_READFAILED = 26,
|
|
|
|
STATUS_STORE_UPDATEFAILED = 27;
|
|
|
|
|
|
|
|
|
|
|
|
///##############################################################
|
|
|
|
/// STATIC ROUTINES
|
|
|
|
|
|
|
|
public static void ShowErrorDialog(Exception exp)
|
|
|
|
{
|
|
|
|
Console.WriteLine("CASA-EXCEPTION: " + exp.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void ShowErrorDialog(int errorCode)
|
|
|
|
{
|
|
|
|
Console.WriteLine("CASA-ERROR: " + errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
///#######################################################################
|
|
|
|
/// READ PLATFORM
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Routine to read the operating system of the target machine.
|
|
|
|
/// IS_LINUX, IS_WINDOWS flags are set.
|
|
|
|
/// Path to Glade file is set in this routine.
|
|
|
|
/// </summary>
|
|
|
|
public static void ReadPlatform()
|
|
|
|
{
|
|
|
|
Logger.DbgLog("GUI:CasaMain.SetGladeFilePath() - BEGIN");
|
|
|
|
|
|
|
|
int platform = (int)Environment.OSVersion.Platform;
|
|
|
|
|
|
|
|
if ( (128 == platform) || (4 == platform) )
|
|
|
|
{
|
|
|
|
IS_LINUX = true;
|
|
|
|
GladeFile = "/opt/novell/CASA/images/casa-1.5.glade";
|
|
|
|
//GladeFile = "./images/casa-1.5.glade";
|
|
|
|
|
|
|
|
if( !File.Exists(GladeFile) )
|
|
|
|
{
|
|
|
|
Logger.DbgLog("GUI:CasaMain.SetGladeFilePath() - ERROR: Glade file could not be found.");
|
|
|
|
//Gtk.Application.Quit();
|
|
|
|
Environment.Exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger.DbgLog("GUI:CasaMain.SetGladeFilePath() - IS_LINUX = " + IS_LINUX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IS_WINDOWS = true;
|
|
|
|
//Common.GladeFile = Environment.GetEnvironmentVariable("HOMEDRIVE") + "\\Program Files\\Novell\\CASA\\images\\casa-1.5.glade";
|
|
|
|
GladeFile = "..\\images\\casa-1.5.glade";
|
|
|
|
if( !File.Exists(GladeFile) )
|
|
|
|
{
|
|
|
|
Logger.DbgLog("GUI:CasaMain.SetGladeFilePath() - ERROR: Glade file could not be found.");
|
|
|
|
Environment.Exit(-1);
|
|
|
|
}
|
|
|
|
Logger.DbgLog("GUI:CasaMain.SetGladeFilePath() - IS_WINDOWS = " + IS_WINDOWS);
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger.DbgLog("GUI:CasaMain.SetGladeFilePath() - END");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///#######################################################################
|
|
|
|
/// SINGLE INSTANCE CHECK
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// MainWindow delete window handler
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public static bool CheckForSingleInstance()
|
|
|
|
{
|
|
|
|
bool bRet=false;;
|
|
|
|
|
|
|
|
if( true == IS_LINUX )
|
|
|
|
{
|
|
|
|
Process mgrProcess = null;
|
|
|
|
StreamReader sReader = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mgrProcess = new Process();
|
|
|
|
ProcessStartInfo mgrProcessStartInfo = new ProcessStartInfo("ps" );
|
|
|
|
mgrProcessStartInfo.Arguments = "h";
|
|
|
|
mgrProcessStartInfo.UseShellExecute = false;
|
|
|
|
mgrProcessStartInfo.RedirectStandardOutput = true;
|
|
|
|
mgrProcess.StartInfo = mgrProcessStartInfo;
|
|
|
|
mgrProcess.Start();
|
|
|
|
mgrProcess.WaitForExit();
|
|
|
|
sReader = mgrProcess.StandardOutput;
|
|
|
|
string str = sReader.ReadLine();
|
|
|
|
int num = 0;
|
|
|
|
while( str != null)
|
|
|
|
{
|
|
|
|
str = sReader.ReadLine();
|
|
|
|
if(str != null)
|
|
|
|
{
|
|
|
|
if(str.EndsWith("CASAManager.exe"))
|
|
|
|
{
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( num > 1 )
|
|
|
|
bRet = true;
|
|
|
|
else
|
|
|
|
bRet = false;
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
Logger.DbgLog("GUI:CasaMain.CheckIfAnotherInstanceIsRunning() " + e.ToString());
|
|
|
|
bRet = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mgrProcess != null)
|
|
|
|
mgrProcess.Close();
|
|
|
|
if(sReader != null)
|
|
|
|
sReader.Close();
|
|
|
|
//return bRet;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if( true == IS_WINDOWS )
|
|
|
|
{
|
|
|
|
bRet = false;
|
|
|
|
//return(false);
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
2005-10-12 17:27:21 +02:00
|
|
|
|
|
|
|
public static bool IsTrayAvailable()
|
|
|
|
{
|
|
|
|
if (true == IS_LINUX)
|
|
|
|
return true;
|
|
|
|
else if (true == IS_WINDOWS)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsArgSet(string[] args, string argToCheck)
|
|
|
|
{
|
|
|
|
if (args != null)
|
|
|
|
{
|
|
|
|
for (int i=0; i<args.Length; i++)
|
|
|
|
{
|
|
|
|
if (argToCheck.Equals(args[i].ToLower()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
///##################################################################
|
|
|
|
/// END OF FILE
|
|
|
|
///##################################################################
|