diff --git a/Sunfish/Sunfish/Middleware/HttpServer.cs b/Sunfish/Sunfish/Middleware/HttpServer.cs index e4e0f28..dd3b283 100644 --- a/Sunfish/Sunfish/Middleware/HttpServer.cs +++ b/Sunfish/Sunfish/Middleware/HttpServer.cs @@ -369,11 +369,6 @@ #endregion #region Output - public void NotFound() - { - Response.StatusCode = 404; - Response.StatusDescription = "Not found"; - } public void Redirect(string to) { @@ -381,6 +376,18 @@ Response.Headers["Location"] = to; } + public void Forbidden() + { + Response.StatusCode = 402; + Response.StatusDescription = "Forbidden"; + } + + public void NotFound() + { + Response.StatusCode = 404; + Response.StatusDescription = "Not found"; + } + public void Write(string s) { if (s != null) diff --git a/Sunfish/Sunfish/Middleware/VFSItem.cs b/Sunfish/Sunfish/Middleware/VFSItem.cs index 4de6bff..972382c 100644 --- a/Sunfish/Sunfish/Middleware/VFSItem.cs +++ b/Sunfish/Sunfish/Middleware/VFSItem.cs @@ -10,8 +10,7 @@ public class VFSItem { private VFSFolder vfolder; - private string name; - + public VFSItem(VFSFolder vfolder, string path, bool isFolder) { this.vfolder = vfolder; @@ -25,6 +24,11 @@ return vfolder.OpenRead(Path); } + public Stream OpenWrite() + { + return vfolder.OpenWrite(Path); + } + public string Path { get; } public string Name { get; } public bool Folder { get; } diff --git a/Sunfish/Sunfish/Program.cs b/Sunfish/Sunfish/Program.cs index ad4cab9..a1b397a 100644 --- a/Sunfish/Sunfish/Program.cs +++ b/Sunfish/Sunfish/Program.cs @@ -7,7 +7,7 @@ { static class Program { - public static string VERSION = "2.0(alpha2)"; + public static string VERSION = "2.0(alpha3)"; private static Form1 mainform; /// /// Punto de entrada principal para la aplicación. diff --git a/Sunfish/Sunfish/Services/WebService.cs b/Sunfish/Sunfish/Services/WebService.cs index daadde7..079cc50 100644 --- a/Sunfish/Sunfish/Services/WebService.cs +++ b/Sunfish/Sunfish/Services/WebService.cs @@ -1,4 +1,6 @@ using DolphinWebXplorer2.Middleware; +using Json.Net; +using System.Collections.Generic; using System.IO; namespace DolphinWebXplorer2.Services @@ -19,6 +21,19 @@ allowSubfolderNavigation = ssc.GetConf(WebServiceConfigurator.CFG_NAVIGATION); } + #region ChildClasses + class WebServiceData + { + public List Files { get; set; } + public string AppTitle => "Sunfish "+Program.VERSION; + } + + class WebServiceFile + { + + } + #endregion + private void ErrorPage(int code, HttpCall call, string text) { call.Response.StatusCode = code; @@ -58,17 +73,37 @@ public override void Process(string path, HttpCall call) { - if (path.EndsWith("/")) + if (path.StartsWith("/|") && allowNavigation) { + path = path.Substring(2); + switch (path) + { + case "data": + call.Write(JsonNet.Serialize(new WebServiceData() + { + Files = new List() + })); + break; + } + } + else if (path.EndsWith("/")) + { + VFSItem idx = vfs.GetItem(path + index); //Directory entry, go for index file or navigation if (index != null) { - VFSItem idx = vfs.GetItem(path + index); if (idx != null) DownloadAt(idx, call); } - //allowNavigation - DownloadAt("/$sunfish/index.html", call); + if (allowNavigation) + { + if (idx != null && idx.Folder) + DownloadAt("/$sunfish/index.html", call); + else + call.NotFound(); + } + else + call.Forbidden(); } else { @@ -82,7 +117,7 @@ } else call.NotFound(); - //DownloadAt("/$sunfish/404.html", call); + //DownloadAt("/$sunfish/404.html", call); } }