ProxyCmdExecutor: Add Enable and Disable buttons.
This commit is contained in:
21
VAR.Toolbox/Code/ProxyCmdExecutors/BaseProxyCmdExecutor.cs
Normal file
21
VAR.Toolbox/Code/ProxyCmdExecutors/BaseProxyCmdExecutor.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public abstract class BaseProxyCmdExecutor : IProxyCmdExecutor
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
public virtual bool Disable()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual bool Enable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract bool ExecuteCmd(string cmd, IOutputHandler outputHandler);
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,9 @@
|
||||
public interface IProxyCmdExecutor : INamed
|
||||
{
|
||||
bool ExecuteCmd(string cmd, IOutputHandler outputHandler);
|
||||
|
||||
bool Enable();
|
||||
|
||||
bool Disable();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public class ProxyCmdExecutorDummy : IProxyCmdExecutor
|
||||
public class ProxyCmdExecutorDummy : BaseProxyCmdExecutor
|
||||
{
|
||||
private readonly string _config;
|
||||
public string Name => "Dummy";
|
||||
public override string Name => "Dummy";
|
||||
|
||||
public ProxyCmdExecutorDummy(string config)
|
||||
{
|
||||
@@ -15,7 +15,7 @@
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
public override bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
{
|
||||
outputHandler.AddLine($"DummyExecution: {cmdString} | {_config}");
|
||||
return true;
|
||||
|
||||
@@ -3,9 +3,9 @@ using System.Data.SqlClient;
|
||||
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public class ProxyCmdExecutorThroughSQLServer : IProxyCmdExecutor
|
||||
public class ProxyCmdExecutorThroughSQLServer : BaseProxyCmdExecutor
|
||||
{
|
||||
public string Name => "SqlServer";
|
||||
public override string Name => "SqlServer";
|
||||
|
||||
private readonly string _connectionString;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
public override bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
{
|
||||
SqlConnection cnx = new SqlConnection(_connectionString);
|
||||
SqlCommand cmd = cnx.CreateCommand();
|
||||
@@ -31,5 +31,53 @@ namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
cnx.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Enable()
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlConnection cnx = new SqlConnection(_connectionString);
|
||||
SqlCommand cmd = cnx.CreateCommand();
|
||||
cmd.CommandText = @"
|
||||
EXEC sp_configure 'show advanced options', '1'
|
||||
RECONFIGURE
|
||||
EXEC sp_configure 'xp_cmdshell', '1'
|
||||
RECONFIGURE
|
||||
";
|
||||
cnx.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
cnx.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Disable()
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlConnection cnx = new SqlConnection(_connectionString);
|
||||
SqlCommand cmd = cnx.CreateCommand();
|
||||
cmd.CommandText = @"
|
||||
EXEC sp_configure 'show advanced options', '1'
|
||||
RECONFIGURE
|
||||
EXEC sp_configure 'xp_cmdshell', '0'
|
||||
RECONFIGURE
|
||||
";
|
||||
cnx.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
cnx.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public class ProxyCmdExecutorWMIC : IProxyCmdExecutor
|
||||
public class ProxyCmdExecutorWMIC : BaseProxyCmdExecutor
|
||||
{
|
||||
public string Name => "WMIC";
|
||||
public override string Name => "WMIC";
|
||||
|
||||
private readonly string _configWMIC;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
_configWMIC = configWMIC;
|
||||
}
|
||||
|
||||
public bool ExecuteCmd(string cmd, IOutputHandler outputHandler)
|
||||
public override bool ExecuteCmd(string cmd, IOutputHandler outputHandler)
|
||||
{
|
||||
string parameters =
|
||||
$" /node:\"{_configWMIC.Replace("\"", "\\\"")}\" process call create \"cmd.exe /c \\\"{cmd.Replace("\"", "\\\"")}\\\"\"";
|
||||
|
||||
56
VAR.Toolbox/UI/Tools/FrmProxyCmd.Designer.cs
generated
56
VAR.Toolbox/UI/Tools/FrmProxyCmd.Designer.cs
generated
@@ -29,10 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.splitMain = new VAR.Toolbox.Controls.CSplitContainer();
|
||||
this.ctrOutput = new VAR.Toolbox.Controls.CtrOutput();
|
||||
this.txtInput = new VAR.Toolbox.Controls.TextBoxMonospace();
|
||||
this.ddlCurrentConfig = new VAR.Toolbox.Controls.CComboBox();
|
||||
this.btnConfig = new VAR.Toolbox.Controls.CButton();
|
||||
this.ctrOutput = new VAR.Toolbox.Controls.CtrOutput();
|
||||
this.btnDisable = new VAR.Toolbox.Controls.CButton();
|
||||
this.btnEnable = new VAR.Toolbox.Controls.CButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitMain)).BeginInit();
|
||||
this.splitMain.Panel1.SuspendLayout();
|
||||
this.splitMain.Panel2.SuspendLayout();
|
||||
@@ -57,12 +59,21 @@
|
||||
// splitMain.Panel2
|
||||
//
|
||||
this.splitMain.Panel2.Controls.Add(this.txtInput);
|
||||
this.splitMain.Size = new System.Drawing.Size(413, 418);
|
||||
this.splitMain.SplitterDistance = 353;
|
||||
this.splitMain.Size = new System.Drawing.Size(556, 503);
|
||||
this.splitMain.SplitterDistance = 424;
|
||||
this.splitMain.SplitterWidth = 10;
|
||||
this.splitMain.TabIndex = 3;
|
||||
this.splitMain.TabStop = false;
|
||||
//
|
||||
// ctrOutput
|
||||
//
|
||||
this.ctrOutput.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.ctrOutput.Location = new System.Drawing.Point(0, 0);
|
||||
this.ctrOutput.Name = "ctrOutput";
|
||||
this.ctrOutput.Size = new System.Drawing.Size(556, 424);
|
||||
this.ctrOutput.TabIndex = 0;
|
||||
this.ctrOutput.Text = "ctrOutput1";
|
||||
//
|
||||
// txtInput
|
||||
//
|
||||
this.txtInput.BackColor = System.Drawing.Color.Black;
|
||||
@@ -74,7 +85,7 @@
|
||||
this.txtInput.Multiline = true;
|
||||
this.txtInput.Name = "txtInput";
|
||||
this.txtInput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.txtInput.Size = new System.Drawing.Size(413, 55);
|
||||
this.txtInput.Size = new System.Drawing.Size(556, 69);
|
||||
this.txtInput.TabIndex = 0;
|
||||
this.txtInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TxtInput_KeyDown);
|
||||
//
|
||||
@@ -89,14 +100,14 @@
|
||||
this.ddlCurrentConfig.FormattingEnabled = true;
|
||||
this.ddlCurrentConfig.Location = new System.Drawing.Point(0, 1);
|
||||
this.ddlCurrentConfig.Name = "ddlCurrentConfig";
|
||||
this.ddlCurrentConfig.Size = new System.Drawing.Size(342, 21);
|
||||
this.ddlCurrentConfig.Size = new System.Drawing.Size(420, 21);
|
||||
this.ddlCurrentConfig.TabIndex = 4;
|
||||
this.ddlCurrentConfig.SelectedIndexChanged += new System.EventHandler(this.DdlCurrentConfig_SelectedIndexChanged);
|
||||
//
|
||||
// btnConfig
|
||||
//
|
||||
this.btnConfig.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnConfig.Location = new System.Drawing.Point(348, 1);
|
||||
this.btnConfig.Location = new System.Drawing.Point(491, 1);
|
||||
this.btnConfig.Name = "btnConfig";
|
||||
this.btnConfig.Size = new System.Drawing.Size(65, 23);
|
||||
this.btnConfig.TabIndex = 5;
|
||||
@@ -104,18 +115,33 @@
|
||||
this.btnConfig.UseVisualStyleBackColor = true;
|
||||
this.btnConfig.Click += new System.EventHandler(this.BtnConfig_Click);
|
||||
//
|
||||
// ctrOutput
|
||||
// btnDisable
|
||||
//
|
||||
this.ctrOutput.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.ctrOutput.Location = new System.Drawing.Point(0, 0);
|
||||
this.ctrOutput.Name = "ctrOutput";
|
||||
this.ctrOutput.Size = new System.Drawing.Size(413, 353);
|
||||
this.ctrOutput.TabIndex = 0;
|
||||
this.ctrOutput.Text = "ctrOutput1";
|
||||
this.btnDisable.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnDisable.Location = new System.Drawing.Point(459, 1);
|
||||
this.btnDisable.Name = "btnDisable";
|
||||
this.btnDisable.Size = new System.Drawing.Size(26, 23);
|
||||
this.btnDisable.TabIndex = 6;
|
||||
this.btnDisable.Text = "D";
|
||||
this.btnDisable.UseVisualStyleBackColor = true;
|
||||
this.btnDisable.Click += new System.EventHandler(this.btnDisable_Click);
|
||||
//
|
||||
// btnEnable
|
||||
//
|
||||
this.btnEnable.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnEnable.Location = new System.Drawing.Point(426, 1);
|
||||
this.btnEnable.Name = "btnEnable";
|
||||
this.btnEnable.Size = new System.Drawing.Size(27, 23);
|
||||
this.btnEnable.TabIndex = 7;
|
||||
this.btnEnable.Text = "E";
|
||||
this.btnEnable.UseVisualStyleBackColor = true;
|
||||
this.btnEnable.Click += new System.EventHandler(this.btnEnable_Click);
|
||||
//
|
||||
// FrmProxyCmd
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(413, 446);
|
||||
this.ClientSize = new System.Drawing.Size(556, 531);
|
||||
this.Controls.Add(this.btnEnable);
|
||||
this.Controls.Add(this.btnDisable);
|
||||
this.Controls.Add(this.btnConfig);
|
||||
this.Controls.Add(this.ddlCurrentConfig);
|
||||
this.Controls.Add(this.splitMain);
|
||||
@@ -138,5 +164,7 @@
|
||||
private VAR.Toolbox.Controls.CComboBox ddlCurrentConfig;
|
||||
private VAR.Toolbox.Controls.CButton btnConfig;
|
||||
private Controls.CtrOutput ctrOutput;
|
||||
private Controls.CButton btnDisable;
|
||||
private Controls.CButton btnEnable;
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,20 @@ namespace VAR.Toolbox.UI.Tools
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEnable_Click(object sender, EventArgs e)
|
||||
{
|
||||
PrepareProxyCmdExecutor();
|
||||
bool result = _proxyCmdExecutor.Enable();
|
||||
AddLine($"Enable: {result}");
|
||||
}
|
||||
|
||||
private void btnDisable_Click(object sender, EventArgs e)
|
||||
{
|
||||
PrepareProxyCmdExecutor();
|
||||
bool result = _proxyCmdExecutor.Disable();
|
||||
AddLine($"Disable: {result}");
|
||||
}
|
||||
|
||||
private void DdlCurrentConfig_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
CleanProxyCmdExecutor();
|
||||
@@ -239,5 +253,6 @@ namespace VAR.Toolbox.UI.Tools
|
||||
}
|
||||
|
||||
#endregion Config
|
||||
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,7 @@
|
||||
<Compile Include="Code\GlobalKeyboardHook.cs" />
|
||||
<Compile Include="Code\HexUtils.cs" />
|
||||
<Compile Include="Code\IEventListener.cs" />
|
||||
<Compile Include="Code\ProxyCmdExecutors\BaseProxyCmdExecutor.cs" />
|
||||
<Compile Include="Code\ProxyCmdExecutors\ProxyCmdExecutorWMIC.cs" />
|
||||
<Compile Include="Code\ReflectionUtils.cs" />
|
||||
<Compile Include="Code\TextCoders\TextCoderBase64Utf8.cs" />
|
||||
|
||||
Reference in New Issue
Block a user