@@ -20,6 +20,8 @@ internal class FtpClientGUI
20
20
21
21
int ClientID = 0 ;
22
22
23
+ bool EnableIcons = ConfigFile . ShowFileIcons ;
24
+
23
25
/// <summary>
24
26
/// Create an instance of Web-FTP client GUI
25
27
/// </summary>
@@ -28,6 +30,14 @@ public FtpClientGUI(HttpRequest ClientRequest)
28
30
{
29
31
this . ClientRequest = ClientRequest ;
30
32
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
+ }
31
41
}
32
42
33
43
/// <summary>
@@ -86,14 +96,15 @@ public FtpClientPage GetWelcomePage()
86
96
87
97
Page . Header = "File Transfer Protocol client" ;
88
98
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>" ;
89
100
90
101
string Form =
91
102
"<form action=\" /!ftp/\" method=\" GET\" name=\" Connect\" >\n " +
92
103
"<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 " +
97
108
"<p><input type=\" submit\" value=\" Let's go!\" ></p>\n " +
98
109
"</center></form>" ;
99
110
@@ -228,7 +239,7 @@ public FtpClientPage GetResultPage()
228
239
if ( cmd . Code != 257 )
229
240
{
230
241
Page . Content += "<p><b>"Print Working Directory" 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>" ;
232
243
return Page ;
233
244
}
234
245
@@ -321,6 +332,7 @@ public FtpClientPage GetResultPage()
321
332
{
322
333
Page . Content += "<tr>" ;
323
334
Page . Content += "<td>" ;
335
+ if ( EnableIcons ) Page . Content += "<img border=\" 0\" src=\" " + GetIconFileName ( "._dir-up" ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
324
336
Page . Content += "[<a href=\" /!ftp/?client=" + ClientID + "&task=listdir&cwd=" + Uri . EscapeDataString ( Backend . WorkdirPath + ".." ) + "\" >..</a>]" ;
325
337
Page . Content += "</td>" ;
326
338
Page . Content += "<td>" ;
@@ -332,23 +344,34 @@ public FtpClientPage GetResultPage()
332
344
foreach ( var Item in FileListTable )
333
345
{
334
346
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
+ }
335
354
336
355
Page . Content += "<tr>" ;
337
356
Page . Content += "<td>" ;
338
357
if ( Item . Directory && ! Item . SymLink )
339
358
{
359
+ Page . Content += IconHtml ;
340
360
Page . Content += "[<a href=\" /!ftp/?client=" + ClientID + "&task=listdir&cwd=" + Uri . EscapeDataString ( Backend . WorkdirPath + FileName ) + "\" >" + FileName + "</a>]" ;
341
361
}
342
362
else if ( Item . Directory && Item . SymLink )
343
363
{
364
+ if ( EnableIcons ) Page . Content += "<img border=\" 0\" src=\" " + GetIconFileName ( "._link" ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
344
365
Page . Content += "<i>[" + FileName + "]</i>" ;
345
366
}
346
367
else if ( ! Item . Directory && Item . SymLink )
347
368
{
369
+ if ( EnableIcons ) Page . Content += "<img border=\" 0\" src=\" " + GetIconFileName ( "._link" ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
348
370
Page . Content += "<i>" + FileName + "</i>" ;
349
371
}
350
372
else
351
373
{
374
+ Page . Content += IconHtml ;
352
375
Page . Content += "<a href=\" /!ftp/?client=" + ClientID + "&task=retr&name=" + Uri . EscapeDataString ( Backend . WorkdirPath + FileName ) + "\" target='_blank'>" + FileName + "</a>" ;
353
376
}
354
377
Page . Content += "</td>" ;
@@ -463,6 +486,35 @@ public FtpClientPage GetDisabledPage()
463
486
Page . Content = "The server administrator has disabled FTP browsing via this proxy." ;
464
487
return Page ;
465
488
}
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
+ }
466
518
}
467
519
468
520
/// <summary>
@@ -483,7 +535,7 @@ public FtpClientPage(string Title = "WebOne: FTP client", string Header = "File
483
535
this . Content = Content ;
484
536
this . ShowFooter = false ;
485
537
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\ " >" ;
487
539
}
488
540
}
489
541
}
0 commit comments