Skip to content

Commit

Permalink
Merge pull request #141 from atauenis/dev
Browse files Browse the repository at this point in the history
Put the v0.17.2 release to master branch
  • Loading branch information
atauenis authored Aug 13, 2024
2 parents c04ed83 + aed5d8d commit 6136b26
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 152 deletions.
3 changes: 2 additions & 1 deletion CertificateUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public static X509Certificate2 MakeChainSignedCert(string certSubject, X509Certi
*/

// Save the certificate and return it.
FakeCertificates.Add(certSubject, certificateWithKey);
if (!FakeCertificates.ContainsKey(certSubject))
FakeCertificates.Add(certSubject, certificateWithKey);
return certificateWithKey;
}
}
Expand Down
24 changes: 21 additions & 3 deletions Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ private Stream RunConverter(LogWriter Log, string ConvCommandLine, Stream InputS
{
if (InputStream != null) new Task(() =>
{
while (InputStream.CanRead && !ConvProc.HasExited) { }; if (!ConvProc.HasExited) ConvProc.Kill(); Console.WriteLine();
while (InputStream.CanRead && !ConvProc.HasExited)
{
Thread.Sleep(5000);
if (InputStream.CanRead && !ConvProc.HasExited) Log.WriteLine(" Converter is still running.");
}
if (!ConvProc.HasExited) ConvProc.Kill(); Console.WriteLine();
}).Start();
new Task(() =>
Expand All @@ -162,6 +167,9 @@ private Stream RunConverter(LogWriter Log, string ConvCommandLine, Stream InputS
#endif
if (File.Exists(SourceTmpFile)) File.Delete(SourceTmpFile);
if (File.Exists(DestinationTmpFile)) File.Delete(DestinationTmpFile);
#if DEBUG
Log.WriteLine(" Remove temporary files if any.");
#endif
}).Start();
return ConvProc.StandardOutput.BaseStream;
}
Expand All @@ -181,8 +189,18 @@ private Stream RunConverter(LogWriter Log, string ConvCommandLine, Stream InputS
#endif
ConvProc.WaitForExit();
InputStream.Close();
if (File.Exists(SourceTmpFile)) File.Delete(SourceTmpFile);
if (File.Exists(DestinationTmpFile)) File.Delete(DestinationTmpFile);

new Task(() =>
{
//wait 1 minute for let client time to download the file
Thread.Sleep(60000);
#if DEBUG
Log.WriteLine(" Remove temporary files.");
#endif
if (File.Exists(SourceTmpFile)) File.Delete(SourceTmpFile);
if (File.Exists(DestinationTmpFile)) File.Delete(DestinationTmpFile);
}).Start();

return File.OpenRead(DestinationTmpFile);
}
}
Expand Down
4 changes: 3 additions & 1 deletion HttpRequestProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ private void ProcessClientRequest(object Backend, LogWriter Logger, string SslLo
catch { Request.Url = new Uri(Request.RawUrl); }
break;
case RequestKind.AlternateProxy:
Request.Url = new Uri(Request.RawUrl[1..]);
string url = Request.RawUrl[1..];
if (url.Contains(":/") && !url.Contains("://")) url = url.Replace(":/", "://");
Request.Url = new Uri(url);
break;
case RequestKind.StandardSslProxy:
Request.Url = null;
Expand Down
25 changes: 22 additions & 3 deletions HttpTransit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,18 @@ public void ProcessTransit()

if (ClientRequest.Kind == HttpUtil.RequestKind.AlternateProxy)
{
// "Local proxy mode"
// "Alternate proxy access mode"
// ex. "Local proxy mode"
string FixedUrl = ClientRequest.RawUrl[1..];
if (FixedUrl.Contains(":/") && !FixedUrl.Contains("://")) FixedUrl = FixedUrl.Replace(":/", "://");
RequestURL = new Uri(FixedUrl);
Log.WriteLine(" Alternate: {0}", RequestURL);
}

if (ClientRequest.Kind == HttpUtil.RequestKind.DirtyAlternateProxy)
{
// "Dirty local proxy mode", try to use last used host: http://localhost/favicon.ico = http://example.com/favicon.ico
// "Dirty alternate proxy access mode", try to use last used host: http://localhost/favicon.ico = http://example.com/favicon.ico
// ex. "Dirty local proxy mode"
string FixedUrl = "http://" + new Uri(LastURL).Host + RequestURL.LocalPath;
RequestURL = new Uri(FixedUrl);
if (RequestURL.Host == "999.999.999.999") { SendError(404, "The proxy server cannot guess domain name."); return; }
Expand Down Expand Up @@ -1186,6 +1189,11 @@ private void SendInternalPage(string InternalPageId, string Arguments)
}
return;
default:
if (InternalPageId.ToLowerInvariant() == "/rovp.htm" && !Program.ToBoolean(ConfigFile.WebVideoOptions["Enable"] ?? "yes"))
{
SendRedirect("/norovp.htm", "ROVP is disabled on this server.");
return;
}
if (CheckInternalContentModification(InternalPageId, ClientRequest.Headers["If-Modified-Since"]))
{
// send 304 Not Modified code
Expand Down Expand Up @@ -2283,7 +2291,18 @@ private void SendStream(Stream Potok, string ContentType, bool Close = true)
if (ex is FileNotFoundException) ErrNo = 404;
SendError(ErrNo, "Cannot retreive stream.<br>" + ex.ToString().Replace("\n", "<br>"));
}
else { Log.WriteLine("<Stream not sent: {0}", ex.Message); }
else
{
try
{
Potok.Close();
Log.WriteLine("<Stream closed: {0}", ex.Message);
}
catch
{
Log.WriteLine("<Stream not sent: {0}", ex.Message);
}
}
}
Dump("End is stream of " + ContentType);
}
Expand Down
72 changes: 52 additions & 20 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static class Program
public static string Protocols = "HTTP 1.1";
public static bool DaemonMode = false;
static bool ShutdownInitiated = false;
static bool RebuildCA = false;

const string CmdLineArgUnnamed = "--wo-short";
static List<KeyValuePair<string, string>> CmdLineOptions = new List<KeyValuePair<string, string>>();
Expand Down Expand Up @@ -147,36 +148,54 @@ static void Main(string[] args)
if (HaveCrtKey) HaveCrtKey = (new FileInfo(ConfigFile.SslCertificate).Length > MinPemLentgh) && (new FileInfo(ConfigFile.SslPrivateKey).Length > MinPemLentgh);
if (HaveCrtKey)
{ Log.WriteLine(false, false, "Using as SSL Certificate Authority: {0}, {1}.", ConfigFile.SslCertificate, ConfigFile.SslPrivateKey); }
else
else if (!RebuildCA)
{
Log.WriteLine(true, false, "Creating root SSL Certificate & Private Key for CA...");
CertificateUtil.MakeSelfSignedCert(ConfigFile.SslCertificate, ConfigFile.SslPrivateKey, ConfigFile.SslRootSubject, ConfigFile.SslHashAlgorithm);
Log.WriteLine(true, false, "CA Certificate: {0}; Key: {1}.", ConfigFile.SslCertificate, ConfigFile.SslPrivateKey);
CreateRootCertificate();
}
RootCertificate = new X509Certificate2(X509Certificate2.CreateFromPemFile(ConfigFile.SslCertificate, ConfigFile.SslPrivateKey).Export(X509ContentType.Pkcs12));
Protocols += ", HTTPS 1.1";
if (!DefaultPACoverriden) DefaultPAC += DefaultPAChttps;

//check validness period
if (RootCertificate.NotAfter < DateTime.Now || RootCertificate.NotBefore > DateTime.Now)
if (RebuildCA)
{
Log.WriteLine(true, false, "Warning! CA Certificate is out of date: {0}-{1}, now {2}.", RootCertificate.NotBefore, RootCertificate.NotAfter, DateTime.Now);
Console.WriteLine();
Log.WriteLine(true, false, "CA Certificate will be new, so import it to browser(s) after build succeeds.");
CreateRootCertificate();
RootCertificate = new X509Certificate2(X509Certificate2.CreateFromPemFile(ConfigFile.SslCertificate, ConfigFile.SslPrivateKey).Export(X509ContentType.Pkcs12));
Log.WriteLine(true, false, "The new certificate is called \"" + RootCertificate.GetNameInfo(X509NameType.SimpleName, false) + "\".");
Log.WriteLine(true, false, "WebOne will now exit.");
Environment.Exit(0);
}

if (RootCertificate.NotAfter < DateTimeOffset.Now.AddDays(ConfigFile.SslCertVaildAfterNow) ||
RootCertificate.NotBefore > DateTimeOffset.Now.AddDays(ConfigFile.SslCertVaildBeforeNow))
try
{
Log.WriteLine(true, false, "Warning! CA Certificate is too fresh or expires too soon. Check configuration.");
RootCertificate = new X509Certificate2(X509Certificate2.CreateFromPemFile(ConfigFile.SslCertificate, ConfigFile.SslPrivateKey).Export(X509ContentType.Pkcs12));
Protocols += ", HTTPS 1.1";
if (!DefaultPACoverriden) DefaultPAC += DefaultPAChttps;

//check validness period
if (RootCertificate.NotAfter < DateTime.Now || RootCertificate.NotBefore > DateTime.Now)
{
Log.WriteLine(true, false, "Warning! CA Certificate is out of date: {0}-{1}, now {2}.", RootCertificate.NotBefore, RootCertificate.NotAfter, DateTime.Now);
}

if (RootCertificate.NotAfter < DateTimeOffset.Now.AddDays(ConfigFile.SslCertVaildAfterNow) ||
RootCertificate.NotBefore > DateTimeOffset.Now.AddDays(ConfigFile.SslCertVaildBeforeNow))
{
Log.WriteLine(true, false, "Warning! CA Certificate is too fresh or expires too soon. Check configuration.");
}
}
catch (Exception CertLoadEx)
{
if (CertLoadEx.InnerException != null)
{
Log.WriteLine(true, false, "Unable to load CA Certificate: {0}.", CertLoadEx.InnerException.Message);
}
else
{
Log.WriteLine(true, false, "Unable to load CA Certificate: {0}.", CertLoadEx.Message);
}
ConfigFile.SslEnable = false;
}
}
catch (Exception CertCreateEx)
{
Log.WriteLine(true, false, "Unable to create CA Certificate: {0}.", CertCreateEx.Message);
/*
Log.WriteLine(true, false, CertCreateEx.StackTrace.Replace("\n", " ; ")); //only for debug purposes at this moment
Log.WriteLine(true, false, "End of CA build error information. HTTPS won't be available!");
*/
ConfigFile.SslEnable = false;
}

Expand All @@ -196,7 +215,7 @@ static void Main(string[] args)
if (!DefaultPACoverriden) DefaultPAC += DefaultPACfooter;
if (!DefaultPACoverriden) ConfigFile.PAC = DefaultPAC;

Log.WriteLine(false, false, "Configured to http://{1}:{2}/, {3}", ConfigFileName, ConfigFile.DefaultHostName, ConfigFile.Port, Protocols);
Log.WriteLine(false, false, "Configured to http://{1}:{2}/, {3}", ConfigFileName, ConfigFile.DefaultHostName, ConfigFile.Port, Protocols);

//initialize server
try
Expand Down Expand Up @@ -280,6 +299,16 @@ static void Main(string[] args)
Shutdown();
}

/// <summary>
/// Create certificate and private key files for WebOne Certificate Authority
/// </summary>
private static void CreateRootCertificate()
{
Log.WriteLine(true, false, "Creating root SSL Certificate & Private Key for CA...");
CertificateUtil.MakeSelfSignedCert(ConfigFile.SslCertificate, ConfigFile.SslPrivateKey, ConfigFile.SslRootSubject, ConfigFile.SslHashAlgorithm);
Log.WriteLine(true, false, "CA Certificate: {0}; Key: {1}.", ConfigFile.SslCertificate, ConfigFile.SslPrivateKey);
}

/// <summary>
/// Shut down server and terminate process
/// </summary>
Expand Down Expand Up @@ -382,6 +411,9 @@ private static void ProcessCommandLine(string[] args)
case "--dump-requests":
//all will be processed in ProcessCommandLineOptions()
break;
case "--rebuild-ca":
RebuildCA = true;
break;
case "--daemon":
DaemonMode = true;
break;
Expand Down
4 changes: 3 additions & 1 deletion WebOne.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Authors>Alexander Tauenis</Authors>
<Version>0.17.1</Version>
<Version>0.17.2</Version>
<VersionSuffix></VersionSuffix> <!--<VersionSuffix>-pre</VersionSuffix>-->
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<Company>World</Company>
Expand Down Expand Up @@ -289,5 +289,7 @@ fi
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>__MACOSX/%(Filename)%(Extension)</Link>
</None>
<None Include="openssl_webone.cnf" CopyToPublishDirectory="Always">
</None>
</ItemGroup>
</Project>
112 changes: 7 additions & 105 deletions WebVideoPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,118 +31,20 @@ public WebVideoPlayer(NameValueCollection Parameters)

if (!Program.ToBoolean(ConfigFile.WebVideoOptions["Enable"] ?? "yes"))
{
Page.Content = "Sorry, proxy server administrator has disabled the online video download feature.";
Page.Content = "It's disabled.";
Page.HttpHeaders.Add("Refresh", "0;url=/norovp.htm");
return;
}

switch (Parameters["type"])
{
case "":
case null:
string Frameset =
"<form action='/!player/' method='GET' target='player_frame' align='center'>" +
" <table border='0' width='100%'>" +
" <tr>" +
" <td align='right'>Video</td>" +
" <td align='center' colspan='4'><input type='text'" +
" size='65' name='url' style='width: 100%'" +
" value='" + SampleUrl + "'></td>" +
" <td align='center' rowspan='3' colspan='2'><input" +
" type='submit' value='Load video'" +
" style='height: 70px;'></td>" +
" </tr>" +
" <tr>" +
" <td align='right'>Format</td>" +
" <td align='left'><select name='f' size='1'" +
" title='Audio/video container'>" +
" <option value='avi'>AVI</option>" +
" <option value='mpeg1video'>MPEG 1</option>" +
" <option value='mpeg2video'>MPEG 2</option>" +
//" <option value='mp4'>MPEG 4</option>" + //muxer does not support non seekable output
" <option selected value='mpegts'>MPEG TS</option>" +
" <option value='asf'>Microsoft ASF</option>" +
" <option value='asf_stream'>Microsoft ASF (stream)</option>" +
//" <option value='mov'>QuickTime</option>" + //muxer does not support non seekable output
" <option value='ogg'>Ogg</option>" + // Theora & Vorbis only
" <option value='webm'>WebM</option>" + // Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.
" <option value='swf'>Macromedia Flash</option>" + // SWF muxer only supports VP6, FLV1 and MJPEG
//" <option value='rm'>RealMedia</option>" + //[rm @ 06cc61c0] Invalid codec tag
//" <option value='3gp'>3GPP</option>" + //muxer does not support non seekable output
" </select></td>" +
" <td align='right'>Codecs</td>" +
" <td align='left'><select name='vcodec' size='1'" +
" title='Video codec'>" +
" <option value='mpeg1video'>MPEG 1</option>" +
" <option value='mpeg2video'>MPEG 2</option>" +
" <option value='mpeg4'>MPEG 4</option>" +
" <option value='wmv1'>WMV 7</option>" +
" <option value='wmv2'>WMV 8</option>" +
" <option value='h263'>H.263</option>" + // Valid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152.
" <option selected value='h264'>H.264 AVC</option>" +
" <option value='hevc'>H.265 HEVC</option>" +
" <option value='theora'>Ogg Theora</option>" +
" <option value='vp8'>VP8</option>" +
" <option value='vp9'>VP9</option>" +
" <option value='mjpeg'>MJPEG</option>" +
" <option value='msvideo1'>MS Video 1</option>" + // width and height must be multiples of 4
" <option value='copy'>(original)</option>" +
" </select> <select name='vf' size='1'" +
" title='Video resolution'>" +
" <option value='scale=\"1080:-1\"'>1080p</option>" +
" <option value='scale=\"720:-1\"'>720p</option>" +
" <option selected value='scale=\"480:-1\"'>480p</option>" +
" <option value='scale=\"360:-1\"'>360p</option>" +
" <option value='scale=\"240:-1\"'>240p</option>" +
" <option value='scale=\"144:-1\"'>144p</option>" +
" <option value='scale=\"1024x768\"'>1024x768</option>" +
" <option value='scale=\"800x600\"'>800x600</option>" +
" <option value='scale=\"640x480\"'>640x480</option>" +
" <option value='scale=\"320x200\"'>320x200</option>" +
" <option value='scale=\"704x576\"'>704x576</option>" +
" <option value='scale=\"352x288\"'>352x288</option>" +
" <option value='scale=\"176x144\"'>176x144</option>" +
" <option value='scale=\"128x96\"'>128x96</option>" +
" <option value='scale=\"-1:-1\"'>(original)</option>" +
" </select> &nbsp; <select name='acodec' size='1'" +
" title='Audio codec'>" +
" <option value='mp2'>MPEG 2</option>" +
" <option selected value='mp3'>MPEG 3</option>" +
" <option value='wmav1'>WMA 1</option>" +
" <option value='wmav2'>WMA 2</option>" +
" <option value='aac'>AAC</option>" +
" <option value='pcm_dvd'>PCM</option>" +
" <option value='vorbis -strict -2'>Ogg Vorbis</option>" + // Current FFmpeg Vorbis encoder only supports 2 channels.
" <option value='opus -strict -2'>Opus</option>" +
" <option value='ra_144'>RealAudio 1</option>" +
" <option value='copy'>(original)</option>" +
" </select> <select name='ac' size='1'" +
" title='Audio channels'>" +
" <option selected value='1'>Mono</option>" +
" <option value='2'>Stereo</option>" +
" </select></td>" +
" <td>(<a href='http://github.com/atauenis/webone/wiki/YouTube-playback'>?</a>)</td>" +
" </tr>" +
" <tr>" +
" <td align='right'></td>" +
" <td align='center' colspan='4'>" +
" <input type='radio'name='type' value='embed'>Embed, " +
" <input type='radio'name='type' value='embedwm' checked>WMP, " +
" <input type='radio'name='type' value='embedvlc'>VLC, " +
" <input type='radio' name='type' value='objectwm'>WinMedia, " +
" <input type='radio' name='type' value='objectns'>NetShow, " +
" <input type='radio' name='type' value='dynimg'>DynImg, " +
" <input type='radio' name='type' value='html5'>HTML5, " +
" <input type='radio' name='type' value='link'>link, " +
" <input type='radio' name='type' value='file'>file" +
" </td>" +
" </tr>" +
" </table>" +
"</form>" +
"" +
"<iframe name='player_frame' src='/!player/?type=" + PreferPage + "' " +
"border='0' width='100%' height='100%' style='border-style: none;'>" +
"Use the toolbar to watch a video.</iframe>"; ;
Page.Content = Frameset;
Page.Content = "<p align=\"center\">";
Page.Content += "<a href=\"/rovp.htm\"><img src=\"/rovp.gif\" alt=\"Click here to open Retro Online Video Player.\"></a>";
Page.Content += "<br><h1 align=\"center\">Retro Online Video Player</h1>";
Page.Content += "</p>";
Page.HttpHeaders.Add("Refresh", "5;url=/rovp.htm");
break;
case "intro":
Page.Content = "<p align='center'><big>Use the toolbar above to watch a video.</big></p>";
Expand Down
Binary file modified Win32-full/yt-dlp.exe
Binary file not shown.
Loading

0 comments on commit 6136b26

Please sign in to comment.