Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable use of HTTPS #637

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Shoko.Desktop/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ private static bool BaseImagesPathIsDefault
}
}

public static string JMMServer_Protocol
{
get
{
string val = Get("ShokoServer_Protocol");
if (!string.IsNullOrEmpty(val)) return val;
// default value
val = "http";
Set("ShokoServer_Protocol", val);
return val;
}
set => Set("ShokoServer_Protocol", value);
}

public static string JMMServer_Address
{
get
Expand Down Expand Up @@ -1764,6 +1778,7 @@ public static void DebugSettingsToLog()
logger.Info($"Episodes_WatchedStatus: {Episodes_WatchedStatus}");
logger.Info($"BaseImagesPath: {BaseImagesPath}");
logger.Info($"BaseImagesPathIsDefault: {BaseImagesPathIsDefault}");
logger.Info($"ShokoServer_Protocol: {JMMServer_Protocol}");
logger.Info($"ShokoServer_Address: {JMMServer_Address}");
logger.Info($"ShokoServer_Port: {JMMServer_Port}");
logger.Info($"ShokoServer_FilePort: {JMMServer_FilePort}");
Expand Down
11 changes: 8 additions & 3 deletions Shoko.Desktop/UserControls/Settings/JMMServerSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand All @@ -23,13 +24,17 @@
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Server}" Margin="0,0,5,2" VerticalAlignment="Center"></TextBlock>
<TextBox Name="txtServer" Width="150" Margin="0,0,5,0" VerticalAlignment="Center"/>
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0">
<CheckBox Name="checkHttps" Content="HTTPS" Margin="0,0,5,2" HorizontalAlignment="Left" Grid.Column="2" VerticalAlignment="Top" IsChecked="False"></CheckBox>
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" Margin="0,0,5,0">
<StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Right" Margin="0,0,5,0">
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Port}" Margin="0,0,5,2" VerticalAlignment="Center"></TextBlock>
<TextBox Name="txtPort" Width="50" Margin="0,0,5,0" VerticalAlignment="Center"/>
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Right" Visibility="Collapsed">
<StackPanel Orientation="Horizontal" Grid.Column="3" Grid.Row="1" HorizontalAlignment="Right" Visibility="Collapsed">
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Settings_FilePort}" Margin="10,5,5,0" VerticalAlignment="Center"></TextBlock>
<TextBox Name="txtFilePort" Width="50" Margin="0,5,5,0" VerticalAlignment="Center"/>
</StackPanel>
Expand All @@ -45,7 +50,7 @@
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Proxy}" Margin="0,0,5,2" VerticalAlignment="Center"/>
<TextBox Name="txtProxy" Width="245" Margin="0,0,5,0" VerticalAlignment="Center" />
</StackPanel>
<CheckBox Name="btnAutoStartLocalJMMServer" Content="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Server_AutoStart}" Margin="0,2,0,0" HorizontalAlignment="Left" Grid.Column="2" VerticalAlignment="Top" IsChecked="True" Click="btnAutoStartLocalJMMServer_Click"/>
<CheckBox Name="btnAutoStartLocalJMMServer" Content="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Server_AutoStart}" Margin="0,2,0,0" HorizontalAlignment="Left" Grid.Column="3" VerticalAlignment="Top" IsChecked="True" Click="btnAutoStartLocalJMMServer_Click"/>

</Grid>
</UserControl>
4 changes: 4 additions & 0 deletions Shoko.Desktop/UserControls/Settings/JMMServerSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public JMMServerSettings()

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(AppSettings.Culture);

checkHttps.IsChecked = AppSettings.JMMServer_Protocol == "https";
txtServer.Text = AppSettings.JMMServer_Address;
txtPort.Text = AppSettings.JMMServer_Port;
//txtFilePort.Text = AppSettings.JMMServer_FilePort;
Expand All @@ -33,6 +34,9 @@ void btnTest_Click(object sender, RoutedEventArgs e)
{
try
{
AppSettings.JMMServer_Protocol = (checkHttps.IsChecked.HasValue && checkHttps.IsChecked.Value)
? "https"
: "http";
AppSettings.JMMServer_Address = txtServer.Text.Trim();
AppSettings.JMMServer_Port = txtPort.Text.Trim();

Expand Down
4 changes: 2 additions & 2 deletions Shoko.Desktop/VideoPlayers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static Tuple<string, List<string>> GetInfo(int vlID, string path, Media m)
name = WebUtility.UrlEncode(name);

string uri =
$"http://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/Stream/{vlID}/{VM_ShokoServer.Instance.CurrentUser.JMMUserID}/false/{name}";
$"{AppSettings.JMMServer_Protocol}://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/Stream/{vlID}/{VM_ShokoServer.Instance.CurrentUser.JMMUserID}/false/{name}";
string fname = Path.GetFileNameWithoutExtension(path);
var p = m?.Parts?.FirstOrDefault();
if (p?.Streams == null) return new Tuple<string, List<string>>(uri, subs);
Expand All @@ -109,7 +109,7 @@ static Tuple<string, List<string>> GetInfo(int vlID, string path, Media m)

try
{
var url = $"http://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/Stream/Filename/{Base64EncodeUrl(s.File)}/{VM_ShokoServer.Instance.CurrentUser.JMMUserID}/false";
var url = $"{AppSettings.JMMServer_Protocol}://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/Stream/Filename/{Base64EncodeUrl(s.File)}/{VM_ShokoServer.Instance.CurrentUser.JMMUserID}/false";
string subtitle = wc.DownloadString(url);
try
{
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Desktop/VideoPlayers/VideoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public string GenerateTemporaryPlayList(List<VM_VideoDetailed> vids)
plsContent += @"[playlist]" + Environment.NewLine;
List<string> lines=new List<string>();

string url = $"http://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/Stream/%s/%s/false/%s";
string url = $"{AppSettings.JMMServer_Protocol}://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/Stream/%s/%s/false/%s";

for (int i = 1; i <= vids.Count; i++)
{
Expand Down
8 changes: 5 additions & 3 deletions Shoko.Desktop/ViewModel/VM_ShokoServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public static bool SettingsAreValid()
if (string.IsNullOrEmpty(AppSettings.JMMServer_Address) || string.IsNullOrEmpty(AppSettings.JMMServer_Port))
return false;

if (!(AppSettings.JMMServer_Protocol.Equals("http") || AppSettings.JMMServer_Protocol.Equals("https")))
return false;

return true;
}
Expand All @@ -122,7 +124,7 @@ public void SetupImageClient()

try
{
_imageClient = ClientFactory.Create<IShokoServerImage>($"http://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/");
_imageClient = ClientFactory.Create<IShokoServerImage>($"{AppSettings.JMMServer_Protocol}://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/");
}
catch (Exception ex)
{
Expand All @@ -139,7 +141,7 @@ public void SetupPlexClient()

try
{
_plexClient = ClientFactory.Create<IShokoServerPlex>($"http://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/");
_plexClient = ClientFactory.Create<IShokoServerPlex>($"{AppSettings.JMMServer_Protocol}://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/");
}
catch (Exception ex)
{
Expand Down Expand Up @@ -223,7 +225,7 @@ public bool SetupClient()

_shokoservices =
ClientFactory.Create<IShokoServer>(
$"http://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/", mappings, proxy:proxy);
$"{AppSettings.JMMServer_Protocol}://{AppSettings.JMMServer_Address}:{AppSettings.JMMServer_Port}/", mappings, proxy:proxy);
// try connecting to see if the server is responding
Instance.ShokoServices.GetServerStatus();
ServerOnline = true;
Expand Down
1 change: 1 addition & 0 deletions Shoko.Desktop/testing.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</rules>
</nlog>
<appSettings>
<add key="JMMServer_Protocol" value="http" />
<add key="JMMServer_Address" value="127.0.0.1" />
<add key="JMMServer_Port" value="8111" />
<add key="ImportFolderMappings" value="" />
Expand Down