Skip to content

Commit

Permalink
Added support for Hex encoded password as a method of authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Aug 25, 2016
1 parent b5ddcca commit c08928d
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 93 deletions.
58 changes: 58 additions & 0 deletions MB_SubSonic/Domain/SubsonicSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Security.Policy;

namespace MusicBeePlugin.Domain
{
public class SubsonicSettings
{
public string Host { get; set; }
public string Port { get; set; }
public string BasePath { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public bool Transcode { get; set; }
public ConnectionProtocol Protocol { get; set; }
public AuthMethod Auth { get; set; }

public enum ConnectionProtocol
{
Http,
Https
}

public enum AuthMethod
{
Token,
HexPass
}
}

public static class SubsonicSettingsExtensions
{
public static string ToFriendlyString(this SubsonicSettings.ConnectionProtocol me)
{
switch (me)
{
case SubsonicSettings.ConnectionProtocol.Http:
return "HTTP";
case SubsonicSettings.ConnectionProtocol.Https:
return "HTTPS";
default:
throw new ArgumentOutOfRangeException(nameof(me), me, null);
}
}

public static string ToFriendlyString(this SubsonicSettings.AuthMethod me)
{
switch (me)
{
case SubsonicSettings.AuthMethod.Token:
return "Token";
case SubsonicSettings.AuthMethod.HexPass:
return "HexPass";
default:
throw new ArgumentOutOfRangeException(nameof(me), me, null);
}
}
}
}
4 changes: 2 additions & 2 deletions MB_SubSonic/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.7.0.0")]
[assembly: AssemblyFileVersion("2.7.0.0")]
[assembly: AssemblyVersion("2.8.0.0")]
[assembly: AssemblyFileVersion("2.8.0.0")]
1 change: 1 addition & 0 deletions MB_SubSonic/SubSonic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Compile Include="AesEncryption.cs" />
<Compile Include="Domain\ConnectStream.cs" />
<Compile Include="Domain\subsonic-rest-api-1.14.0.Designer.cs" />
<Compile Include="Domain\SubsonicSettings.cs" />
<Compile Include="MusicBeeInterface.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down
48 changes: 41 additions & 7 deletions MB_SubSonic/SubSonicPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using MusicBeePlugin.Domain;
using MusicBeePlugin.Properties;

namespace MusicBeePlugin
Expand All @@ -19,6 +20,7 @@ public partial class Plugin
private CheckBox _transcode;
private TextBox _username;
private ComboBox _protocol;
private ComboBox _authMethodBox;

// ReSharper disable once UnusedMember.Global
public PluginInfo Initialise(IntPtr apiInterfacePtr)
Expand All @@ -34,7 +36,7 @@ public PluginInfo Initialise(IntPtr apiInterfacePtr)
// current only applies to artwork, lyrics or instant messenger name that appears in the provider drop down selector or target Instant Messenger
_about.Type = PluginType.Storage;
_about.VersionMajor = 2; // your plugin version
_about.VersionMinor = 7;
_about.VersionMinor = 8;
_about.Revision = 0;
_about.MinInterfaceVersion = MinInterfaceVersion;
_about.MinApiRevision = MinApiRevision;
Expand All @@ -56,6 +58,7 @@ public bool Configure(IntPtr panelHandle)
var protocolWidth = TextRenderer.MeasureText(@"HTTPS", configPanel.Font).Width*2;
var hostTextBoxWidth = TextRenderer.MeasureText(@"my-server-name.subsonic.org", configPanel.Font).Width;
var portTextBoxWidth = TextRenderer.MeasureText(@"844345", configPanel.Font).Width;
var authMethodWidth = TextRenderer.MeasureText(@"Hex enc. password", configPanel.Font).Width;
var spacer = TextRenderer.MeasureText("X", configPanel.Font).Width;
const int firstRowPosY = 0;
var secondRowPosY = TextRenderer.MeasureText("FirstRowText", configPanel.Font).Height*2;
Expand Down Expand Up @@ -135,15 +138,29 @@ public bool Configure(IntPtr panelHandle)
_protocol.Bounds = new Rectangle(_host.Left, firstRowPosY, protocolWidth, _protocol.Height);
_protocol.Items.Add("HTTP");
_protocol.Items.Add("HTTPS");
_protocol.SelectedItem = Subsonic.Protocol;
_protocol.SelectedItem = Subsonic.Protocol.ToFriendlyString();
_protocol.DropDownStyle = ComboBoxStyle.DropDownList;

var authMethodLabel = new Label
{
AutoSize = true,
Location = new Point(_password.Left + _password.Width + spacer, fifthRowPosY + 2),
Text = @"Auth:"
};

_authMethodBox = new ComboBox();
_authMethodBox.Bounds = new Rectangle(authMethodLabel.Left + TextRenderer.MeasureText(authMethodLabel.Text, configPanel.Font).Width, fifthRowPosY, authMethodWidth, _authMethodBox.Height);
_authMethodBox.Items.Add("Token based");
_authMethodBox.Items.Add("Hex enc. password");
_authMethodBox.SelectedIndex = (int)Subsonic.AuthMethod;
_authMethodBox.DropDownStyle = ComboBoxStyle.DropDownList;

configPanel.Controls.AddRange(new Control[]
{
protocolLabel, _protocol, _host, hostPrompt, portPrompt, _port, _basePath, basePathPrompt, _username, usernamePrompt, _password,
passwordPrompt, _transcode
passwordPrompt, _transcode, _authMethodBox, authMethodLabel
});
_transcode.Location = new Point(_port.Left, passwordPrompt.Top - 2);
_transcode.Location = new Point(_port.Left, basePathPrompt.Top - 2);
configPanel.Width = _transcode.Right + spacer;
return true;
}
Expand All @@ -152,8 +169,25 @@ public bool Configure(IntPtr panelHandle)
// its up to you to figure out whether anything has changed and needs updating
public void SaveSettings()
{
var setHostSuccess = Subsonic.SetHost(_host.Text, _port.Text, _basePath.Text,
_username.Text, _password.Text, _transcode.Checked, _protocol.SelectedItem.ToString());
var settings = new SubsonicSettings
{
Host = _host.Text,
Port = _port.Text,
BasePath = _basePath.Text,
Username = _username.Text,
Password = _password.Text,
Transcode = _transcode.Checked,
Protocol =
_protocol.SelectedItem.ToString().Equals("HTTP")
? SubsonicSettings.ConnectionProtocol.Http
: SubsonicSettings.ConnectionProtocol.Https,
Auth =
_authMethodBox.SelectedIndex.Equals(0)
? SubsonicSettings.AuthMethod.Token
: SubsonicSettings.AuthMethod.HexPass
};

var setHostSuccess = Subsonic.SetHost(settings);
if (setHostSuccess)
{
DeleteCacheFile();
Expand All @@ -165,7 +199,7 @@ public void SaveSettings()
var message = error?.Message;
if (!string.IsNullOrEmpty(message))
{
MessageBox.Show(_host, $"Error: {message}", @"Subsonic Plugin", MessageBoxButtons.OK,
MessageBox.Show(_host, $@"Error: {message}", @"Subsonic Plugin", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
Expand Down

0 comments on commit c08928d

Please sign in to comment.