317 lines
7.8 KiB
C#
317 lines
7.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Specialized;
|
|
|
|
using Gtk;
|
|
using Glade;
|
|
|
|
|
|
using Novell.CASA;
|
|
using Novell.CASA.CASAPolicy;
|
|
|
|
namespace Novell.CASA.GUI
|
|
{
|
|
/// <summary>
|
|
/// Summary description for PolicyDialog.
|
|
/// </summary>
|
|
public class PersistentPolicyDialog
|
|
{
|
|
|
|
private TreeStore tsPersistentList = new TreeStore(typeof(string));
|
|
private TreeStore tsNonPersistentList = new TreeStore(typeof(string));
|
|
|
|
private PersistencePol policy = null;
|
|
private bool bChanged = false;
|
|
|
|
|
|
#region Glade Widgets
|
|
|
|
[Glade.Widget]
|
|
Gtk.TreeView tvPersistentList,
|
|
tvNonPersistentList;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Dialog dialogPersistentPolicy;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Button applybuttonPersistent,
|
|
buttonMakeNonPersistent,
|
|
buttonMakePersistent,
|
|
helpbuttonPolicy;
|
|
|
|
#endregion
|
|
|
|
public PersistentPolicyDialog()
|
|
{
|
|
//
|
|
// TODO: Add constructor logic here
|
|
//
|
|
}
|
|
|
|
public void ShowDialog()
|
|
{
|
|
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogPersistentPolicy", null);
|
|
gxmlTemp.Autoconnect(this);
|
|
|
|
activateMoveButtons(false, false);
|
|
applybuttonPersistent.Sensitive = false;
|
|
|
|
// load store
|
|
SecretStore ss = SecretStore.GetInstance();
|
|
StringCollection sc = ss.EnumerateSecretIDs();
|
|
StringEnumerator senum = sc.GetEnumerator();
|
|
|
|
// load policy
|
|
policy = (PersistencePol)ICASAPol.GetPolicy(CASAPolType.PERSISTENCE_POL);
|
|
if (policy == null)
|
|
{
|
|
policy = new PersistencePol("Platform", "PersistentPath_NOT USED", 10);
|
|
}
|
|
|
|
while (senum.MoveNext())
|
|
{
|
|
string sSecretID = senum.Current;
|
|
if (policy.GetSecretPolicy(sSecretID, "Persistent", true))
|
|
{
|
|
tsPersistentList.AppendValues(sSecretID);
|
|
}
|
|
else
|
|
{
|
|
//tsNonPersistentList.AppendValues(sSecretID);
|
|
}
|
|
}
|
|
|
|
// display non-persistent IDs
|
|
ArrayList al = policy.GetNonpersistentSecretIDs();
|
|
for (int i=0; i<al.Count; i++)
|
|
{
|
|
tsNonPersistentList.AppendValues((string)al[i]);
|
|
}
|
|
|
|
|
|
// set sortable
|
|
tsPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
|
|
tsNonPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
|
|
|
|
// add Columnts
|
|
tvPersistentList.AppendColumn("Persistent Secrets", new CellRendererText(), "text", 0);
|
|
tvPersistentList.Columns[0].Clickable = true;
|
|
tvPersistentList.Columns[0].Clicked +=new EventHandler(PersistentPolicyDialog_Clicked);
|
|
tvPersistentList.RowActivated +=new RowActivatedHandler(tvPersistentList_RowActivated);
|
|
tvPersistentList.ButtonReleaseEvent += new ButtonReleaseEventHandler(tvPersistentList_ButtonReleaseEvent);
|
|
|
|
|
|
tvNonPersistentList.AppendColumn("Non-Persistent Secrets", new CellRendererText(), "text", 0);
|
|
tvNonPersistentList.Columns[0].Clickable = true;
|
|
tvNonPersistentList.Columns[0].Clicked +=new EventHandler(NonPersistentPolicyDialog_Clicked);
|
|
tvNonPersistentList.RowActivated +=new RowActivatedHandler(tvNonPeristentList_RowActivated);
|
|
tvNonPersistentList.ButtonReleaseEvent +=new ButtonReleaseEventHandler(tvNonPersistentList_ButtonReleaseEvent);
|
|
|
|
|
|
// hook up the model
|
|
tvPersistentList.Model = tsPersistentList;
|
|
tvNonPersistentList.Model = tsNonPersistentList;
|
|
}
|
|
|
|
|
|
public void on_helpbuttonPersistent_clicked(object obj, EventArgs arg)
|
|
{
|
|
Common.ShowHelpUrl("CreSecretPol.htm");
|
|
}
|
|
|
|
public void on_applybuttonPersistent_clicked(object obj, EventArgs args)
|
|
{
|
|
if (bChanged)
|
|
{
|
|
// enumerate ts, setting the policy for each secret
|
|
TreeIter iter;
|
|
|
|
if(tsPersistentList.GetIterFirst(out iter))
|
|
{
|
|
do
|
|
{
|
|
string secretID = (string)tsPersistentList.GetValue(iter,0);
|
|
|
|
// set policy
|
|
if (policy != null)
|
|
{
|
|
policy.SetSecretPolicy(secretID, "Persistent", "True", "True");
|
|
}
|
|
}
|
|
while( tsPersistentList.IterNext(ref iter) );
|
|
}
|
|
|
|
if(tsNonPersistentList.GetIterFirst(out iter))
|
|
{
|
|
do
|
|
{
|
|
string secretID = (string)tsNonPersistentList.GetValue(iter,0);
|
|
|
|
// set policy
|
|
if (policy != null)
|
|
{
|
|
policy.SetSecretPolicy(secretID, "Persistent", "False", "True");
|
|
}
|
|
}
|
|
while( tsNonPersistentList.IterNext(ref iter) );
|
|
}
|
|
|
|
// save policy now
|
|
ICASAPol.SetPolicy(policy);
|
|
bChanged = false;
|
|
applybuttonPersistent.Sensitive = false;
|
|
activateMoveButtons(false, false);
|
|
}
|
|
}
|
|
|
|
public void on_okbutton_clicked(object obj, EventArgs args)
|
|
{
|
|
if (bChanged)
|
|
{
|
|
on_applybuttonPersistent_clicked(obj, args);
|
|
}
|
|
|
|
closeDialog();
|
|
}
|
|
|
|
public void on_cancelbutton_clicked(object obj, EventArgs args)
|
|
{
|
|
closeDialog();
|
|
}
|
|
|
|
private void closeDialog()
|
|
{
|
|
if (dialogPersistentPolicy != null)
|
|
{
|
|
dialogPersistentPolicy.Destroy();
|
|
}
|
|
}
|
|
|
|
private void tvPersistentList_RowActivated(object o, RowActivatedArgs args)
|
|
{
|
|
MakeNonPersistent();
|
|
}
|
|
|
|
private void MakeNonPersistent()
|
|
{
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
String selected;
|
|
|
|
if( tvPersistentList.Selection.GetSelected (out model, out iter) )
|
|
{
|
|
selected = (string) model.GetValue (iter, 0);
|
|
tsNonPersistentList.AppendValues(selected);
|
|
tsPersistentList.Remove(ref iter);
|
|
bChanged = true;
|
|
applybuttonPersistent.Sensitive = true;
|
|
}
|
|
}
|
|
|
|
public void on_buttonMakeNonPersistent_clicked(object o, EventArgs args)
|
|
{
|
|
MakeNonPersistent();
|
|
}
|
|
|
|
public void on_buttonMakePersistent_clicked(object o, EventArgs args)
|
|
{
|
|
MakePersistent();
|
|
}
|
|
|
|
private void tvNonPeristentList_RowActivated(object o, RowActivatedArgs args)
|
|
{
|
|
MakePersistent();
|
|
}
|
|
|
|
private void MakePersistent()
|
|
{
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
String selected;
|
|
|
|
if( tvNonPersistentList.Selection.GetSelected (out model, out iter) )
|
|
{
|
|
selected = (string) model.GetValue (iter, 0);
|
|
tsPersistentList.AppendValues(selected);
|
|
tsNonPersistentList.Remove(ref iter);
|
|
bChanged = true;
|
|
applybuttonPersistent.Sensitive = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void PersistentPolicyDialog_Clicked(object sender, EventArgs e)
|
|
{
|
|
int iColID = 0;
|
|
Gtk.SortType sortType = Gtk.SortType.Ascending;
|
|
|
|
bool bReturn = tsPersistentList.GetSortColumnId(out iColID, out sortType);
|
|
if (bReturn)
|
|
{
|
|
if (sortType == Gtk.SortType.Ascending)
|
|
{
|
|
tsPersistentList.SetSortColumnId(0, Gtk.SortType.Descending);
|
|
}
|
|
else
|
|
{
|
|
tsPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NonPersistentPolicyDialog_Clicked(object sender, EventArgs e)
|
|
{
|
|
int iColID = 0;
|
|
Gtk.SortType sortType = Gtk.SortType.Ascending;
|
|
|
|
bool bReturn = tsNonPersistentList.GetSortColumnId(out iColID, out sortType);
|
|
if (bReturn)
|
|
{
|
|
if (sortType == Gtk.SortType.Ascending)
|
|
{
|
|
tsNonPersistentList.SetSortColumnId(0, Gtk.SortType.Descending);
|
|
}
|
|
else
|
|
{
|
|
tsNonPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void tvPersistentList_ButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
|
|
{
|
|
activateMoveButtons(true, false);
|
|
}
|
|
|
|
private void tvNonPersistentList_ButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
|
|
{
|
|
activateMoveButtons(false, true);
|
|
}
|
|
|
|
|
|
private void activateMoveButtons(bool bMakeNonPersist, bool bMakePersist)
|
|
{
|
|
if (bMakeNonPersist)
|
|
{
|
|
buttonMakeNonPersistent.Sensitive = true;
|
|
}
|
|
else
|
|
{
|
|
buttonMakeNonPersistent.Sensitive = false;
|
|
}
|
|
|
|
if (bMakePersist)
|
|
{
|
|
buttonMakePersistent.Sensitive = true;
|
|
}
|
|
else
|
|
{
|
|
buttonMakePersistent.Sensitive = false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|