Skip to content

Commit

Permalink
Adding Root Drive Check
Browse files Browse the repository at this point in the history
Added a check to see if psf is running in the root drive. This will
prompt for an override to continue running.
  • Loading branch information
Ben0xA committed Aug 18, 2014
1 parent dab145e commit 5d2c608
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
113 changes: 71 additions & 42 deletions poshsecframework/Interface/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public partial class frmMain : Form
private bool cancelscan = false;
private bool restart = false;
private bool shown = false;
private bool cont = true;
private Utility.Schedule schedule = new Utility.Schedule(1000);
private string loaderrors = "";
private Collection<String> enabledmods = new Collection<string>();
Expand Down Expand Up @@ -75,53 +76,71 @@ public frmMain()
InitializeComponent();
lvwSystems.ListViewItemSorter = lvwSorter;
this.Enabled = false;
stat = new Interface.frmStartup();
stat.Show();
stat.Refresh();
}

private void frmMain_Shown(object sender, EventArgs e)
{
stat.SetStatus("Initializing, please wait...");
scnr.ScanComplete += scnr_ScanComplete;
scnr.ScanCancelled += scnr_ScanCancelled;
scnr.ScanUpdate += scnr_ScanUpdate;
schedule.ItemUpdated += schedule_ItemUpdated;
schedule.ScriptInvoked += schedule_ScriptInvoked;
schedule.ScheduleRemoved += schedule_ScheduleRemoved;

stat.SetStatus("Checking Settings, please wait...");
CheckSettings();
if (poshsecframework.Properties.Settings.Default.FirstTime)
if (IsRootDrive())
{
restart = true;
stat.Hide();
FirstTimeSetup();
cont = false;
if (MessageBox.Show(StringValue.RootDrive, "Running in root drive!", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
cont = true;
}
}
if (restart)
if (cont)
{
Application.Restart();
this.Close();
stat = new Interface.frmStartup();
stat.Show();
stat.Refresh();
}
else
}

private void frmMain_Shown(object sender, EventArgs e)
{
if (cont)
{
Initialize();
stat.Show();
stat.SetStatus("Loading Networks, please wait...");
GetNetworks();
GetAlerts();
stat.SetStatus("Initializing, please wait...");
scnr.ScanComplete += scnr_ScanComplete;
scnr.ScanCancelled += scnr_ScanCancelled;
scnr.ScanUpdate += scnr_ScanUpdate;
schedule.ItemUpdated += schedule_ItemUpdated;
schedule.ScriptInvoked += schedule_ScriptInvoked;
schedule.ScheduleRemoved += schedule_ScheduleRemoved;

stat.SetStatus("Checking Settings, please wait...");
CheckSettings();
if (poshsecframework.Properties.Settings.Default.FirstTime)
{
restart = true;
stat.Hide();
FirstTimeSetup();
}
if (restart)
{
Application.Restart();
this.Close();
}
else
{
Initialize();
stat.Show();
stat.SetStatus("Loading Networks, please wait...");
GetNetworks();
GetAlerts();
}
if (loaderrors != "")
{
DisplayOutput(StringValue.ImportError + Environment.NewLine + loaderrors, null, false, false, false, true);
}
shown = true;
stat.Close();
stat.Dispose();
stat = null;
this.Enabled = true;
this.Focus();
schedule.Start();
}
if (loaderrors != "")
else
{
DisplayOutput(StringValue.ImportError + Environment.NewLine + loaderrors, null, false, false, false, true);
this.Close();
}
shown = true;
stat.Close();
stat.Dispose();
stat = null;
this.Enabled = true;
this.Focus();
schedule.Start();
}

private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
Expand Down Expand Up @@ -216,6 +235,18 @@ private void Initialize()
InitSyslog();
}

private bool IsRootDrive()
{
bool rtn = false;
DirectoryInfo dinfo = new DirectoryInfo(Application.StartupPath);
if (dinfo.Parent == null)
{
rtn = true;
}
dinfo = null;
return rtn;
}

void ghChecker_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
CheckLastModified();
Expand Down Expand Up @@ -2777,9 +2808,7 @@ public bool CancelIPScan
{
get { return cancelscan; }
}
#endregion


#endregion

}
}
1 change: 1 addition & 0 deletions poshsecframework/Strings/StringValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static class StringValue
public const string AlertBalloon = "You have an alert!";
public const string AlertsBalloon = "You have {0} alerts!";
public const string PSRequirements = "It appears that your environment is not configured correctly for PoshSec Framework to work correctly.\r\nYou need PowerShell 3.0 (Windows Management Framework 3.0) and Microsoft .NET 4.5\r\nPlease download and install WMF 3.0 before running PoshSec Framework.";
public const string RootDrive = "You are running PoshSec Framework from the root of a disk drive. It is recommended to put PoshSec Framework in a subfolder.\r\n\r\nFor example: C:\\psf\\\r\n\r\nDo you wish to continue anyway?";
public const string ActiveScriptsRunning = "You have active scripts running. If you exit, all running scripts will be terminated. Are you sure you want to exit?";
public const string ReloadScriptsRunning = "Can not reload the framework because there are scripts running. Please stop all scripts before issuing the reload command again.";
public const string SettingScriptsRunning = "You can not change the settings while scripts or commands are running. Please stop any commands or scripts and then try again.";
Expand Down

0 comments on commit 5d2c608

Please sign in to comment.