Skip to content

Commit e0f8ae3

Browse files
authored
Merge v0.17.5 to master branch
2 parents c743a91 + 30301b4 commit e0f8ae3

File tree

212 files changed

+673
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+673
-98
lines changed

ConfigFile.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ static class ConfigFile
198198
/// </summary>
199199
public static bool EnableWebFtp = true;
200200

201+
/// <summary>
202+
/// Enable or disable file type icons in Web-FTP client
203+
/// </summary>
204+
public static bool ShowFileIcons = true;
205+
201206
/// <summary>
202207
/// Use Microsoft HTTPAPI (HttpListener) for processing incoming traffic
203208
/// </summary>
@@ -223,6 +228,28 @@ static class ConfigFile
223228
/// </summary>
224229
public static bool OpenForLocalIPs = false;
225230

231+
/// <summary>
232+
/// Do not prefer HTTPS protocol even for HTTPS connections
233+
/// </summary>
234+
public static bool DontPreferHTTPS = false;
235+
236+
237+
238+
/// <summary>
239+
/// Enable emulation of Microsoft ActiveX components search engine (MSICD)
240+
/// </summary>
241+
public static bool ActivexGalleryEmulation = true;
242+
243+
/// <summary>
244+
/// Emulate Microsoft ActiveX components search engine (MSICD) at URLs
245+
/// </summary>
246+
public static List<string> ActivexGalleryUrls = new();
247+
248+
/// <summary>
249+
/// Database of OLE Controls, DirectShow Codecs, etc, servicing by http://activex.microsoft.com/objects/ocget.dll (MSICD)
250+
/// </summary>
251+
public static Dictionary<string, string> ActivexGalleryCLSIDs = new();
252+
226253

227254

228255
/// <summary>

ConfigFileLoader.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ public static void ProcessConfiguration()
291291
case "EnableWebFtp":
292292
ConfigFile.EnableWebFtp = ToBoolean(Option.Value);
293293
break;
294+
case "ShowFileIcons":
295+
ConfigFile.ShowFileIcons = ToBoolean(Option.Value);
296+
break;
294297
case "UseMsHttpApi":
295298
ConfigFile.UseMsHttpApi = ToBoolean(Option.Value);
296299
break;
@@ -307,6 +310,9 @@ public static void ProcessConfiguration()
307310
else
308311
Log.WriteLine(true, false, "Warning: Incorrect ContentDirectory '{0}'.", ContentDirName);
309312
break;
313+
case "DontPreferHTTPS":
314+
ConfigFile.DontPreferHTTPS = ToBoolean(Option.Value);
315+
break;
310316
default:
311317
Log.WriteLine(true, false, "Warning: Unknown server option {0} in {1}.", Option.Key, Option.Location);
312318
break;
@@ -595,6 +601,61 @@ public static void ProcessConfiguration()
595601
ConfigFile.Http10Only.Add(Line.RawString);
596602
}
597603
break;
604+
case "ActivexGallery":
605+
case "ActiveXGallery":
606+
foreach (ConfigFileOption Line in Section.Options)
607+
{
608+
if (Line.HaveKeyValue)
609+
{
610+
if (Line.Key.ToLowerInvariant() == "ActiveXGalleryEmulation".ToLowerInvariant())
611+
{
612+
//Enable/Disable
613+
ConfigFile.ActivexGalleryEmulation = ToBoolean(Line.Value);
614+
}
615+
else
616+
{
617+
//Component information
618+
string CLSIDString = Line.Key.Replace("{", "").Replace("}", "").ToUpperInvariant();
619+
620+
if (!System.Text.RegularExpressions.Regex.IsMatch(CLSIDString.ToLowerInvariant(), "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"))
621+
{
622+
if (!System.Text.RegularExpressions.Regex.IsMatch(CLSIDString.ToLowerInvariant(), @"[a-z0-9.\-_]*/[a-z0-9.\-_]"))
623+
{
624+
Log.WriteLine(true, false, "Warning: Incorrect Internet Component GUID or type at {0}.", Line.Location);
625+
continue;
626+
}
627+
}
628+
629+
if (Line.Key.EndsWith(",latest"))
630+
{
631+
//CLSID,latest (latest version of corresponding component)
632+
string VersionString = Line.Value.Replace(',', '.');
633+
if (!Version.TryParse(VersionString, out Version Ver))
634+
{
635+
Log.WriteLine(true, false, "Warning: Incorrect Internet Component latest version at {0}.", Line.Location);
636+
continue;
637+
}
638+
639+
if (ConfigFile.ActivexGalleryCLSIDs.ContainsKey(CLSIDString)) ConfigFile.ActivexGalleryCLSIDs.Remove(CLSIDString); // allow overwrite it
640+
ConfigFile.ActivexGalleryCLSIDs.Add(CLSIDString, VersionString);
641+
continue;
642+
}
643+
//CLSID or CLSID,language (path to corresponding MSICD CAB file)
644+
if (ConfigFile.ActivexGalleryCLSIDs.ContainsKey(CLSIDString)) ConfigFile.ActivexGalleryCLSIDs.Remove(CLSIDString); // allow overwrite it
645+
ConfigFile.ActivexGalleryCLSIDs.Add(CLSIDString, Line.Value);
646+
}
647+
}
648+
else if (System.Text.RegularExpressions.Regex.IsMatch(Line.RawString, "^http://"))
649+
{
650+
//Codebase search engine URL
651+
ConfigFile.ActivexGalleryUrls.Add(Line.RawString);
652+
}
653+
else
654+
{
655+
Log.WriteLine(true, false, "Warning: Incorrect Microsoft codebase search engine option at {0}.", Line.Location);
656+
}
657+
}
658+
break;
598659
case "FixableURL":
599660
case "FixableType":
600661
case "ContentPatch":

FtpClientGUI.cs

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal class FtpClientGUI
2020

2121
int ClientID = 0;
2222

23+
bool EnableIcons = ConfigFile.ShowFileIcons;
24+
2325
/// <summary>
2426
/// Create an instance of Web-FTP client GUI
2527
/// </summary>
@@ -28,6 +30,14 @@ public FtpClientGUI(HttpRequest ClientRequest)
2830
{
2931
this.ClientRequest = ClientRequest;
3032
RequestArguments = System.Web.HttpUtility.ParseQueryString(ClientRequest.Url.Query);
33+
34+
if(EnableIcons)
35+
{
36+
if (!File.Exists(ConfigFile.ContentDirectory + "/filetypes/_dir.gif")) EnableIcons = false;
37+
if (!File.Exists(ConfigFile.ContentDirectory + "/filetypes/_dir-up.gif")) EnableIcons = false;
38+
if (!File.Exists(ConfigFile.ContentDirectory + "/filetypes/_file.gif")) EnableIcons = false;
39+
if (!File.Exists(ConfigFile.ContentDirectory + "/filetypes/_link.gif")) EnableIcons = false;
40+
}
3141
}
3242

3343
/// <summary>
@@ -86,14 +96,15 @@ public FtpClientPage GetWelcomePage()
8696

8797
Page.Header = "File Transfer Protocol client";
8898
Page.Content = "<p>Welcome to space of computer files, directories and servers. Here you'll be able to download something to your PC from FTP servers without quitting a web browser.</p>";
99+
Page.HtmlHeaders += "\n<style>.formlabel { width: 80px; display: inline-block; display:-moz-inline-block; display:-moz-inline-stack; text-align: right; }</style>";
89100

90101
string Form =
91102
"<form action=\"/!ftp/\" method=\"GET\" name=\"Connect\">\n" +
92103
"<center><input type=\"hidden\" name=\"client\" value=\"-1\">\n" +
93-
"<p>Server: <input type=\"text\" size=\"23\" name=\"server\" value=\"\"><br>\n" +
94-
"or URI: <input type=\"text\" size=\"23\" name=\"uri\" value=\"\"></p>\n" +
95-
"<p>Username: <input type=\"text\" size=\"20\" name=\"user\" value=\"anonymous\"><br>\n" +
96-
"Password: <input type=\"password\" size=\"20\" name=\"pass\"value=\"user@domain.su\"></p>\n" +
104+
"<p><label class=\"formlabel\" for=\"server\">Server:</label> <input type=\"text\" size=\"23\" name=\"server\" id=\"server\" value=\"\"><br>\n" +
105+
"<label class=\"formlabel\" for=\"uri\">or URI:</label> <input type=\"text\" size=\"23\" name=\"uri\" id=\"uri\" value=\"\"></p>\n" +
106+
"<p><label class=\"formlabel\" for=\"user\">Username:</label> <input type=\"text\" size=\"20\" name=\"user\" id=\"user\" value=\"anonymous\"><br>\n" +
107+
"<label class=\"formlabel\" for=\"pass\">Password:</label> <input type=\"password\" size=\"20\" name=\"pass\" id=\"pass\" value=\"user@domain.su\"></p>\n" +
97108
"<p><input type=\"submit\" value=\"Let's go!\"></p>\n" +
98109
"</center></form>";
99110

@@ -228,7 +239,7 @@ public FtpClientPage GetResultPage()
228239
if (cmd.Code != 257)
229240
{
230241
Page.Content += "<p><b>&quot;Print Working Directory&quot; command has returned an unexpected result:</b> " + cmd.ToString() + "</p>";
231-
Page.Content += "<p>Return to <a href=\"/!ftp/\"><b>start page</b></a> and try to connect again.</p>";
242+
Page.Content += "<p>Reload this page or return to <a href=\"/!ftp/\"><b>start page</b></a> and try to connect again.</p>";
232243
return Page;
233244
}
234245

@@ -321,6 +332,7 @@ public FtpClientPage GetResultPage()
321332
{
322333
Page.Content += "<tr>";
323334
Page.Content += "<td>";
335+
if (EnableIcons) Page.Content += "<img border=\"0\" src=\"" + GetIconFileName("._dir-up") + "\" width=\"16px\" height=\"16px\" class=\"fileicon\"> ";
324336
Page.Content += "[<a href=\"/!ftp/?client=" + ClientID + "&task=listdir&cwd=" + Uri.EscapeDataString(Backend.WorkdirPath + "..") + "\">..</a>]";
325337
Page.Content += "</td>";
326338
Page.Content += "<td>";
@@ -332,23 +344,34 @@ public FtpClientPage GetResultPage()
332344
foreach (var Item in FileListTable)
333345
{
334346
string FileName = Item.Name;
347+
string IconHtml = "";
348+
349+
if (EnableIcons)
350+
{
351+
if (Item.Directory) IconHtml = "<img border=\"0\" src=\"" + GetIconFileName("._dir") + "\" width=\"16px\" height=\"16px\" class=\"fileicon\"> ";
352+
else IconHtml = "<img border=\"0\" src=\"" + GetIconFileName(FileName) + "\" width=\"16px\" height=\"16px\" class=\"fileicon\"> ";
353+
}
335354

336355
Page.Content += "<tr>";
337356
Page.Content += "<td>";
338357
if (Item.Directory && !Item.SymLink)
339358
{
359+
Page.Content += IconHtml;
340360
Page.Content += "[<a href=\"/!ftp/?client=" + ClientID + "&task=listdir&cwd=" + Uri.EscapeDataString(Backend.WorkdirPath + FileName) + "\">" + FileName + "</a>]";
341361
}
342362
else if (Item.Directory && Item.SymLink)
343363
{
364+
if (EnableIcons) Page.Content += "<img border=\"0\" src=\"" + GetIconFileName("._link") + "\" width=\"16px\" height=\"16px\" class=\"fileicon\"> ";
344365
Page.Content += "<i>[" + FileName + "]</i>";
345366
}
346367
else if (!Item.Directory && Item.SymLink)
347368
{
369+
if (EnableIcons) Page.Content += "<img border=\"0\" src=\"" + GetIconFileName("._link") + "\" width=\"16px\" height=\"16px\" class=\"fileicon\"> ";
348370
Page.Content += "<i>" + FileName + "</i>";
349371
}
350372
else
351373
{
374+
Page.Content += IconHtml;
352375
Page.Content += "<a href=\"/!ftp/?client=" + ClientID + "&task=retr&name=" + Uri.EscapeDataString(Backend.WorkdirPath + FileName) + "\" target='_blank'>" + FileName + "</a>";
353376
}
354377
Page.Content += "</td>";
@@ -463,6 +486,35 @@ public FtpClientPage GetDisabledPage()
463486
Page.Content = "The server administrator has disabled FTP browsing via this proxy.";
464487
return Page;
465488
}
489+
490+
/// <summary>
491+
/// Get content file name for icon, describing the file in Web-FTP directory listing
492+
/// </summary>
493+
/// <param name="OriginalFileName">File name on remote FTP server</param>
494+
string GetIconFileName(string OriginalFileName)
495+
{
496+
if (!EnableIcons) throw new InvalidOperationException("File type icons are disabled.");
497+
if (!OriginalFileName.Contains('.'))
498+
{
499+
return "/filetypes/_file.gif";
500+
}
501+
string ext = OriginalFileName.Substring(OriginalFileName.LastIndexOf(".") + 1);
502+
if (string.IsNullOrWhiteSpace(ext))
503+
{
504+
return "/filetypes/_file.gif";
505+
}
506+
else
507+
{
508+
try
509+
{
510+
if (File.Exists(ConfigFile.ContentDirectory + "/filetypes/" + ext + ".gif"))
511+
return "/filetypes/" + ext + ".gif";
512+
else
513+
return "/filetypes/_file.gif";
514+
}
515+
catch { return "/filetypes/_file.gif"; }
516+
}
517+
}
466518
}
467519

468520
/// <summary>
@@ -483,7 +535,7 @@ public FtpClientPage(string Title = "WebOne: FTP client", string Header = "File
483535
this.Content = Content;
484536
this.ShowFooter = false;
485537
this.AddCss = false;
486-
this.HtmlHeaders = @"<link href=""/webone.css"" rel=""stylesheet""/><link rel=""shortcut icon"" href=""/ftpfav.ico"" type=""image/x-icon"">";
538+
this.HtmlHeaders = "<link href=\"/webone.css\" rel=\"stylesheet\"/>\n<link rel=\"shortcut icon\" href=\"/ftpfav.ico\" type=\"image/x-icon\">";
487539
}
488540
}
489541
}

HttpOperation.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class HttpOperation
2323
/// </summary>
2424
internal string Method { get; set; }
2525

26+
/// <summary>
27+
/// Use HTTPS protocol for this operation
28+
/// </summary>
29+
internal bool SecureConnection { get; set; }
30+
2631
/// <summary>
2732
/// Full HTTP client request
2833
/// </summary>
@@ -57,6 +62,7 @@ class HttpOperation
5762
internal HttpOperation(LogWriter Log)
5863
{
5964
this.Log = Log;
65+
this.SecureConnection = false;
6066
}
6167

6268
/// <summary>
@@ -124,7 +130,7 @@ internal void SendRequest()
124130

125131
foreach (string SslHost in ConfigFile.ForceHttps)
126132
{
127-
if (Request.RequestUri.Host.StartsWith(SslHost))
133+
if (Request.RequestUri.Host.StartsWith(SslHost) || SecureConnection)
128134
{
129135
UriBuilder ub = new(Request.RequestUri);
130136
ub.Scheme = "https";
@@ -134,6 +140,7 @@ internal void SendRequest()
134140
#if DEBUG
135141
Log.WriteLine(" Willfully secure request.");
136142
#endif
143+
break;
137144
}
138145
}
139146

0 commit comments

Comments
 (0)