Skip to content

Commit

Permalink
Add option to run the firewall utility
Browse files Browse the repository at this point in the history
Also the firewall utility has been modified for v1.0.0
  • Loading branch information
kelsos committed Nov 18, 2016
1 parent b5b2deb commit c6ae84d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 37 deletions.
28 changes: 21 additions & 7 deletions MBRC.sln
@@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mbrc-plugin", "plugin\mbrc-plugin.csproj", "{F5D46BA1-6F21-40EF-9695-46105CCACD08}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "firewall-utility", "firewall-utility\firewall-utility.csproj", "{48E9B838-6430-459B-9B44-D1E3548DF393}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,17 +27,29 @@ Global
{F5D46BA1-6F21-40EF-9695-46105CCACD08}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F5D46BA1-6F21-40EF-9695-46105CCACD08}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F5D46BA1-6F21-40EF-9695-46105CCACD08}.Release|Win32.ActiveCfg = Release|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Debug|Win32.ActiveCfg = Debug|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Debug|Win32.Build.0 = Debug|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Release|Any CPU.Build.0 = Release|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Release|Win32.ActiveCfg = Release|Any CPU
{48E9B838-6430-459B-9B44-D1E3548DF393}.Release|Win32.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs
BuildVersion_BuildVersioningStyle = None.None.Increment.None
BuildVersion_ConfigurationName = Release
BuildVersion_UpdateAssemblyVersion = True
BuildVersion_UpdateFileVersion = True
BuildVersion_UseGlobalSettings = False
BuildVersion_UseUniversalClock = True
BuildVersion_UseGlobalSettings = False
BuildVersion_UpdateFileVersion = True
BuildVersion_UpdateAssemblyVersion = True
BuildVersion_ConfigurationName = Release
BuildVersion_BuildVersioningStyle = None.None.Increment.None
BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs
EndGlobalSection
EndGlobal
32 changes: 8 additions & 24 deletions firewall-utility/Program.cs
Expand Up @@ -12,15 +12,6 @@
/// </summary>
internal class Program
{
/// <summary>
/// This is the HTTP port argument identifier.
/// </summary>
private const string Http = "-h";

/// <summary>
/// The name of the HTTP rule.
/// </summary>
private const string HttpRule = "MusicBee Remote: HTTP Port";

/// <summary>
/// This is the socket port argument identifier.
Expand All @@ -30,7 +21,7 @@ internal class Program
/// <summary>
/// The name of the socket rule.
/// </summary>
private const string SocketRule = "MusicBee Remote: Websocket Port";
private const string SocketRule = "MusicBee Remote: Listening Port";

/// <summary>
/// Creates a firewall rule.
Expand Down Expand Up @@ -101,30 +92,23 @@ private static void Main(string[] args)
{
var dictionary = new Dictionary<string, int>();

if (args.Length == 4)
if (args.Length == 2)
{
for (var i = 0; i < args.Length; i += 2)
{
var key = args[i];
int val;
int.TryParse(args[i + 1], out val);
dictionary.Add(key, val);
}
var key = args[0];
int val;
int.TryParse(args[0 + 1], out val);
dictionary.Add(key, val);

int httpPort;
int socketPort;
if (dictionary.TryGetValue(Http, out httpPort) && dictionary.TryGetValue(Socket, out socketPort))
if (dictionary.TryGetValue(Socket, out socketPort))
{
CreateFirewallRuleForPort(socketPort, SocketRule);
CreateFirewallRuleForPort(httpPort, HttpRule);
return;
}
}

Console.WriteLine("{0} -s 3000 -h 8188\n", AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("{0} -s 3000", AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("\t -s: \t This will create the rule for the socket server port");
Console.WriteLine("\t -h: \t This will create the rule for the HTTP REST server port\n");
Console.WriteLine("Both arguments are required");
Console.WriteLine("**For the rules to be created administrative rights are required**");
}
}
Expand Down
16 changes: 12 additions & 4 deletions plugin/AndroidRemote/Settings/UserSettings.cs
Expand Up @@ -31,6 +31,8 @@ public class UserSettings

private const string LogsEnabled = "logs_enabled";

private const string UpdateFirewallNode = "update_firewall";

private uint listeningPort;


Expand Down Expand Up @@ -99,10 +101,10 @@ private UserSettings()
public string CurrentVersion { get; set; }

/// <summary>
/// Since there is an issue with the existing search for a number of users
/// an alternative implementation exists.
/// </summary>
public bool AlternativeSearch { get; set; } = false;
/// Since there is an issue with the existing search for a number of users
/// an alternative implementation exists.
/// </summary>
public bool AlternativeSearch { get; set; } = false;

/// <summary>
/// Enables Debug logging to the production version of the plugin
Expand All @@ -112,6 +114,7 @@ private UserSettings()
public static string LogFilePath = "\\mbrc.log";

public string FullLogPath => StoragePath + LogFilePath;
public bool UpdateFirewall { get; set; }

/// <summary>
///
Expand Down Expand Up @@ -226,6 +229,7 @@ private void WriteApplicationSetting(XmlDocument document)
WriteNodeValue(document, Selection, FilterSelection.ToString());
WriteNodeValue(document, LibrarySource, ((short) Source).ToString());
WriteNodeValue(document, LogsEnabled, DebugLogEnabled.ToString());
WriteNodeValue(document, UpdateFirewallNode, UpdateFirewall.ToString());
}

private string ReadNodeValue(XmlNode document, string name)
Expand Down Expand Up @@ -256,6 +260,10 @@ public void LoadSettings()
bool debugEnabled;
bool.TryParse(ReadNodeValue(document, LogsEnabled), out debugEnabled);
DebugLogEnabled = debugEnabled;

bool updateFirewall;
bool.TryParse(ReadNodeValue(document, UpdateFirewallNode), out updateFirewall);
UpdateFirewall = updateFirewall;


short source;
Expand Down
13 changes: 13 additions & 0 deletions plugin/InfoWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions plugin/InfoWindow.cs
Expand Up @@ -76,6 +76,7 @@ private void InfoWindowLoad(object sender, EventArgs e)
}

debugEnabled.Checked = settings.DebugLogEnabled;
firewallCheckbox.Checked = settings.UpdateFirewall;

_logger.Debug($"Selected source is -> {settings.Source}");
}
Expand Down Expand Up @@ -155,7 +156,14 @@ private void HandleSaveButtonClick(object sender, EventArgs e)
UserSettings.Instance.IpAddressList = new List<string>(_ipAddressBinding);
break;
}

UserSettings.Instance.UpdateFirewall = firewallCheckbox.Checked;
UserSettings.Instance.SaveSettings();

if (firewallCheckbox.Checked)
{
UpdateFirewallRules(UserSettings.Instance.ListeningPort);
}
}

private void AddAddressButtonClick(object sender, EventArgs e)
Expand Down Expand Up @@ -218,5 +226,21 @@ public void SetOnDebugSelectionListener(IOnDebugSelectionChanged listener)
{
this.listener = listener;
}

/// <summary>
/// When called it will execute the firewall-utility passing the port settings
/// needed by the plugin.
/// </summary>
public void UpdateFirewallRules(uint port)
{
var startInfo = new ProcessStartInfo(
$"{AppDomain.CurrentDomain.BaseDirectory}\\Plugins\\firewall-utility.exe")
{
Verb = "runas",
Arguments =
$"-s {port}"
};
Process.Start(startInfo);
}
}
}
2 changes: 1 addition & 1 deletion plugin/Properties/AssemblyInfo.cs
Expand Up @@ -36,4 +36,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.0.1444")]
[assembly: AssemblyVersion("1.0.0.1446")]
2 changes: 1 addition & 1 deletion plugin/mbrc-plugin.csproj
Expand Up @@ -44,7 +44,7 @@
<UpdateAssemblyFileVersion>False</UpdateAssemblyFileVersion>
<UpdateAssemblyInfoVersion>False</UpdateAssemblyInfoVersion>
<AssemblyVersionSettings>None.None.None.Increment</AssemblyVersionSettings>
<AssemblyVersion>1.0.0.1444</AssemblyVersion>
<AssemblyVersion>1.0.0.1446</AssemblyVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down

0 comments on commit c6ae84d

Please sign in to comment.