Ejemplo n.º 1
0
 static RootService()
 {
     LinkHome = new WebUILink()
     {
         Icon    = "home",
         Link    = "/",
         Tooltip = "Root",
     };
 }
Ejemplo n.º 2
0
        private void WriteIndex(string path, VFSItem dir, HttpCall call)
        {
            List <WebUILink> items    = new List <WebUILink>();
            List <string>    fileList = new List <string>();

            foreach (VFSItem vd in dir.ListDirectories())
            {
                items.Add(new WebUILink()
                {
                    Icon        = "/$sunfish/folder.png",
                    Name        = vd.Name,
                    Description = "Directory",
                    Link        = vd.Name + "/",
                    Style       = "directory",
                    Actions     = new WebUILink[] {
                        new WebUILink()
                        {
                            Icon    = "archive",
                            Tooltip = "Download as zip",
                            //Click="sunfish.openFile(this)"
                            Link = vd.Name + "?action=zip"
                        },
                        readOnly?null:new WebUILink()
                        {
                            Icon    = "drive_file_rename_outline",
                            Tooltip = "Rename",
                            Click   = "sunfish.renameFile(this)"
                        },
                        allowDelete?new WebUILink()
                        {
                            Icon    = "delete",
                            Tooltip = "Delete folder",
                            Click   = "sunfish.deleteFile(this);"
                        }:null
                    }
                });
            }
            fileList.Clear();
            foreach (VFSItem vf in dir.ListFiles())
            {
                items.Add(new WebUILink()
                {
                    Icon        = vf.Name + "?action=icon",
                    Name        = vf.Name,
                    Description = "<span class='size'>" + vf.Length.ToSize() + "</span> <span class='info'>(" + MimeTypes.GetMimeType(Path.GetExtension(vf.Name)) + ")</span>",
                    Link        = vf.Name,
                    Actions     = new WebUILink[] {
                        allowExec?new WebUILink()
                        {
                            Icon    = "api",
                            Tooltip = "Open in server",
                            Click   = "sunfish.openFile(this)"
                        }:null,
                        readOnly?null:new WebUILink()
                        {
                            Icon    = "drive_file_rename_outline",
                            Tooltip = "Rename",
                            Click   = "sunfish.renameFile(this)"
                        },
                        allowDelete?new WebUILink()
                        {
                            Icon    = "delete",
                            Tooltip = "Delete file",
                            Click   = "sunfish.deleteFile(this)"
                        }:null
                    }
                });;
            }
            Dictionary <string, object> data = new Dictionary <string, object>();

            data["Breadcrumb"] = GetBreadcrumb(path);
            data["Actions"]    = new WebUILink[] {
                readOnly?null : new WebUILink()
                {
                    Icon    = "create_new_folder",
                    Tooltip = "New folder",
                    Click   = "sunfish.newFolder(this)",
                },
                readOnly?null : new WebUILink()
                {
                    Icon    = "note_add",
                    Tooltip = "New file",
                    Click   = "sunfish.newFile(this)",
                },
                readOnly?null : new WebUILink()
                {
                    Icon    = "upload",
                    Tooltip = "Upload. Drop files or fonders here",
                    Click   = "sunfish.uploadFile(this)",
                    //Style="upload-drop",
                }
            };
            data["Items"]   = items;
            data["Include"] = "<script src=\"/$sunfish/sunfish-directory.js\"></script>";
            WebUI.WriteTemplate("directory-index", call, data);
        }
Ejemplo n.º 3
0
        public override void Process(string path, HttpCall call)
        {
            if (path == "/")
            {
                // Root page
                if (ShowMenu)
                {
                    List <WebUILink> items = new List <WebUILink>();
                    foreach (SunfishService s in Sunfish.Services)
                    {
                        if (!s.Enabled)
                        {
                            continue;
                        }
                        items.Add(new WebUILink()
                        {
                            Icon        = "/$sunfish/folder.png",
                            Name        = s.Configuration.Name,
                            Description = s.Configuration.Location,
                            Link        = s.Configuration.Location,
                        });
                    }
                    Dictionary <string, object> data = new Dictionary <string, object>();
                    data["Breadcrumb"] = new WebUILink[] { LinkHome };
                    //data["Actions"] = actions;
                    data["Items"] = items;
                    WebUI.WriteTemplate("directory-index", call, data);
                }
                else
                {
                    call.Response.StatusCode = 404;
                }
            }
            else if (path.StartsWith(DIR_COMMON))
            {
                path = path.Substring(DIR_COMMON.Length);
                if (path == "Sunfish.exe")
                {
                    // Self copy
                    call.Response.ContentType = "application/x-msdownload";
                    call.Write(File.ReadAllBytes(Assembly.GetExecutingAssembly().Location));
                }
                else if (path == "info")
                {
                    WebUI.WriteTemplate("sunfish-header", call, null);
                    call.Write("<p>Sunfish " + Program.VERSION + " (C) XWolfOverride</p>");
#if DEBUG
                    call.Write("<p>Debug build</p>");
                    if (WebUI.EXTERNAL_RESOURCES)
                    {
                        call.Write("<p>Using external resources</p>");
                    }
                    else
                    {
                        call.Write("<p>Using internal resources</p>");
                    }
#else
                    call.Write("<p>Release build</p>");
#endif
                    if (WebUI.Ready)
                    {
                        call.Write("<p>Resources loaded succesfully</p>");
                    }
                    else
                    {
                        call.Write("<p>No resources</p>");
                    }
                    call.Write("<p><b><a href='info/seal'>Seal resources</a></b></p>");
                    WebUI.WriteTemplate("sunfish-footer", call, null);
                }
                else if (path == "info/seal")
                {
                    WebUI.Seal();
                    call.Response.StatusCode          = 307;
                    call.Response.Headers["Location"] = "/$sunfish/info";
                }
                else

                {
                    // Internal Resources
                    WebUI.WriteResource(path, call);
                }
            }
            else
            {
                call.HTTPNotFound();
            }
        }