Skip to content

Commit

Permalink
Support ExecAction
Browse files Browse the repository at this point in the history
  • Loading branch information
gotdibbs committed Dec 13, 2018
1 parent 2864fe4 commit edb5c19
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 15 deletions.
99 changes: 85 additions & 14 deletions Imposter.Fiddler/Imposter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
using Imposter.Fiddler.Model;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading;

namespace Imposter.Fiddler
{
public class Imposter : IAutoTamper
public class Imposter : IFiddlerExtension, IAutoTamper, IHandleExecAction
{
private bool _isStarted = false;
private Guid? _autoStartProfileId;

public bool IsEnabled { get; set; }
public bool EnableAutoReload { get; set; }
public bool EnableAutoFilter { get; set; } = true;

private ImposterSettings _settings = null;
private List<Profile> _enabledProfiles = null;
private Dictionary<Guid, ToolStripMenuItem> _profileMenuMap = new Dictionary<Guid, ToolStripMenuItem>();

private ToolStripMenuItem _imposterMenu;
private ToolStripMenuItem _profiles;
Expand All @@ -44,6 +44,13 @@ public void OnLoad()
FiddlerApplication.UI.MainMenuStrip.Dock = DockStyle.Top;
FiddlerApplication.UI.MainMenuStrip.Items.Add(_imposterMenu);
FiddlerApplication.UI.Controls.Add(FiddlerApplication.UI.MainMenuStrip);

_isStarted = true;

if (_autoStartProfileId != null)
{
StartProfile(_autoStartProfileId.Value);
}
}

private void Start()
Expand Down Expand Up @@ -146,6 +153,7 @@ private void LoadProfileItems(string checkedProfile = null)
}

_profiles.DropDownItems.Add(item);
_profileMenuMap.Add(profile.ProfileId, item);
}
}

Expand Down Expand Up @@ -201,15 +209,7 @@ private void ProfileEnable_Click(object sender, EventArgs e)

if (item.Checked)
{
IsEnabled = true;
_isEnabled.Checked = true;
_isEnabled.Enabled = true;
_autoReload.Enabled = true;
_autoFilter.Enabled = true;

_enabledProfiles.Add(_settings.Profiles.Where(p => p.ProfileId == (Guid)parent.Tag).First());

Start();
StartProfile((Guid)parent.Tag);
}
else
{
Expand Down Expand Up @@ -294,6 +294,7 @@ private void ProfileDelete_Click(object sender, EventArgs e)

// Remove the item from the menu
parent.Dispose();
_profileMenuMap.Remove(profile.ProfileId);

_settings.Profiles = _settings.Profiles.Where(p => p.ProfileId != (Guid)parent.Tag).ToList();
_settings.Save();
Expand Down Expand Up @@ -421,6 +422,76 @@ private string GetFileNames(string[] paths)
return string.Join(", ", paths);
}

public bool OnExecAction(string action)
{
if (!action.StartsWith("imposter"))
{
return false;
}

var parts = action.Split('.');

if (parts.Length < 2)
{
return false;
}

var profileId = Guid.Parse(parts[1]);

var profile = _settings.Profiles.FirstOrDefault(p => p.ProfileId == profileId);

if (!_isStarted)
{
_autoStartProfileId = profileId;
return true;
}

if (profileId == Guid.Empty || profile == null)
{
Start();
}
else
{
StartProfile(profileId);
}

return true;
}

private void StartProfile(Guid profileId)
{
var profile = _settings.Profiles.FirstOrDefault(p => p.ProfileId == profileId);

if (profileId == Guid.Empty || profile == null)
{
return;
}

IsEnabled = true;
_isEnabled.Checked = true;
_isEnabled.Enabled = true;
_autoReload.Enabled = true;
_autoFilter.Enabled = true;

if (_profileMenuMap.ContainsKey(profileId))
{
_profileMenuMap[profileId].Checked = true;

foreach (ToolStripMenuItem item in _profileMenuMap[profileId].DropDownItems)
{
if (item.Text == "&Enable")
{
item.Checked = true;
break;
}
}
}

_enabledProfiles.Add(profile);

Start();
}

#region Not Implemented

public void AutoTamperRequestAfter(Session oSession)
Expand Down
1 change: 0 additions & 1 deletion Imposter.Fiddler/Models/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
Expand Down

0 comments on commit edb5c19

Please sign in to comment.