Ejemplo n.º 1
0
        public RawModule()
            : base("/rawdata")
        {
            Get["/dir/{path*}"] = x => {
                var p     = x.path;
                var model = new DirectoryLister("/" + p, false).FullList2;
                var json  = JsonConvert.SerializeObject(model);
                return(json);
            };

            Get["/dir/filelist/{path*}"] = x => {
                var           p     = x.path;
                var           list  = new DirectoryLister("/" + p, false).FullList2;
                List <string> model = (from d in list
                                       where d.isFile == true
                                       select d.path).ToList();
                var json = JsonConvert.SerializeObject(model);
                return(json);
            };

            Get["/file/content/{path*}"] = x => {
                var p     = x.path;
                var model = FileSystem.ReadFile(p);
                var json  = JsonConvert.SerializeObject(model);
                return(json);
            };
        }
Ejemplo n.º 2
0
        public DirectoryModule()
            : base("/dir")
        {
            this.RequiresAuthentication();

            Get["/tree/{path*}"] = x => {
                var            p    = x.path;
                DirectoryModel dirs = new DirectoryModel();
                dirs.parents  = new DirectoryLister("/" + p, false).ParentList.Reverse();
                dirs.children = new DirectoryLister("/" + p, false).FullList;
                return(View["page-dir", dirs]);
            };

            Get["/tttt/{path*}"] = x => {
                var p = x.path;
                HashSet <string> directories = new DirectoryLister("/" + p, false).FullList;
                var i = directories.FirstOrDefault();
                return(Response.AsText(i));
            };

            Get["/directory/tree/{path*}"] = x => {
                var p = x.path;
                HashSet <string> directories = new DirectoryLister("/" + p, true).FullList;
                return(View["page-dir", directories.ToList()]);
            };

            Get["/directory/watch/"] = x => {
                return(View["page-directories-watch"]);
            };
        }
Ejemplo n.º 3
0
        public RawModule()
            : base("/rawdata")
        {
            Get["/dir/{path*}"] = x => {
                var p = x.path;
                var model = new DirectoryLister("/" + p, false).FullList2;
                var json = JsonConvert.SerializeObject(model);
                return json;
            };

            Get["/dir/filelist/{path*}"] = x => {
                var p = x.path;
                var list = new DirectoryLister("/" + p, false).FullList2;
                List<string> model = (from d in list
                                      where d.isFile == true
                                      select d.path).ToList();
                var json = JsonConvert.SerializeObject(model);
                return json;
            };

            Get["/file/content/{path*}"] = x => {
                var p = x.path;
                var model = FileSystem.ReadFile(p);
                var json = JsonConvert.SerializeObject(model);
                return json;
            };
        }
Ejemplo n.º 4
0
        public TestModule() : base("/test")
        {
            Get["/"] = x => {
                return(Response.AsText("Hello World!"));
            };

            Get["/acl"] = x => {
                var c = new DirectoryLister("/sys", false).GetFileACL();
                return(Response.AsJson(c));
            };

            //Get["/dir"] = x => {
            //    DirectoryInfo root = new DirectoryInfo("/cfg");
            //    DirectoryLister.WalkDirectoryTree(root);
            //    var i = DirectoryLister.cache;
            //    return Response.AsJson(i);
            //};
        }
Ejemplo n.º 5
0
        public SystemModule()
            : base("/system")
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.Hostname = Command.Launch("hostname", "").output;
                vmod.Domainname = Command.Launch("hostname", "-f").output;
                vmod.Timezone = Command.Launch("timedatectl", "").output;
                vmod.Timeserver = "time.server.net";
                vmod.Language = "English";
                vmod.TCPport = "";
                vmod.MaxProcesses = "2";
                vmod.AlternateHostnames = "";
                vmod.SSHPort = "22";
                return View["_page-system", vmod];
            };

            Get["/mounts"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.MountRunning = Mount.Running;
                vmod.MountAntd = Mount.Antd;
                return View["_page-system-mounts", vmod];
            };

            Get["/sysctl"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.Sysctl = VHStatus.Sysctl(Sysctl.Stock, Sysctl.Running, Sysctl.Antd);
                return View["_page-system-sysctl", vmod];
            };

            Get["/conf"] = x => {
                dynamic vmod = new ExpandoObject();
                HashSet<DirItemModel> etcList = new DirectoryLister("/etc", true).FullList2;
                HashSet<DirItemModel> cfgList = new DirectoryLister("/antd/etc", true).FullList2;
                List<dynamic> nl = new List<dynamic>() { };
                foreach (DirItemModel dir in etcList) {
                    dynamic imod = new ExpandoObject();
                    imod.isFile = dir.isFile;
                    imod.etcPath = dir.path;
                    bool hasCfg;
                    string cfgPath;
                    string cfgName;
                    string p = dir.path.ConvertPathToFileName().Replace("D:", "");
                    string c = (from i in cfgList
                                where i.name == p
                                select i.path).FirstOrDefault();
                    if (c == null) {
                        hasCfg = false;
                        cfgPath = "";
                        cfgName = "";
                    }
                    else {
                        hasCfg = true;
                        cfgPath = c;
                        cfgName = Path.GetFileName(c);
                    }
                    imod.hasCfg = hasCfg;
                    imod.cfgPath = cfgPath;
                    imod.cfgName = cfgName;
                    nl.Add(imod);
                }
                vmod.Conf = nl;
                return View["_page-system-conf", vmod];
            };

            Post["/export/file/{path*}"] = x => {
                string path = x.path;
                ConfigEtc.Export(path);
                return Response.AsJson("done");
            };

            Get["/read/file/{path*}"] = x => {
                string path = x.path;
                string text = FileSystem.ReadFile(path.RemoveDriveLetter());
                return Response.AsJson(text);
            };

            Post["/file"] = x => {
                string path = this.Request.Form.FilePath;
                string content = this.Request.Form.FileContent;
                ConfigEtc.EditFile(path, content);
                return Response.AsRedirect("/system");
            };

            Post["/sysctl/{param}/{value}"] = x => {
                string param = x.param;
                string value = x.value;
                var output = Sysctl.Config(param, value);
                return Response.AsJson(output);
            };

            Get["/wizard"] = x => {
                dynamic vmod = new ExpandoObject();
                return View["page-wizard", vmod];
            };
        }
Ejemplo n.º 6
0
        public SystemModule()
            : base("/system")
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.Hostname           = Command.Launch("hostname", "").output;
                vmod.Domainname         = Command.Launch("hostname", "-f").output;
                vmod.Timezone           = Command.Launch("timedatectl", "").output;
                vmod.Timeserver         = "time.server.net";
                vmod.Language           = "English";
                vmod.TCPport            = "";
                vmod.MaxProcesses       = "2";
                vmod.AlternateHostnames = "";
                vmod.SSHPort            = "22";
                return(View["_page-system", vmod]);
            };

            Get["/mounts"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.MountRunning = Mount.Running;
                vmod.MountAntd    = Mount.Antd;
                return(View["_page-system-mounts", vmod]);
            };

            Get["/sysctl"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.Sysctl = VHStatus.Sysctl(Sysctl.Stock, Sysctl.Running, Sysctl.Antd);
                return(View["_page-system-sysctl", vmod]);
            };

            Get["/conf"] = x => {
                dynamic vmod = new ExpandoObject();
                HashSet <DirItemModel> etcList = new DirectoryLister("/etc", true).FullList2;
                HashSet <DirItemModel> cfgList = new DirectoryLister("/antd/etc", true).FullList2;
                List <dynamic>         nl      = new List <dynamic>()
                {
                };
                foreach (DirItemModel dir in etcList)
                {
                    dynamic imod = new ExpandoObject();
                    imod.isFile  = dir.isFile;
                    imod.etcPath = dir.path;
                    bool   hasCfg;
                    string cfgPath;
                    string cfgName;
                    string p = dir.path.ConvertPathToFileName().Replace("D:", "");
                    string c = (from i in cfgList
                                where i.name == p
                                select i.path).FirstOrDefault();
                    if (c == null)
                    {
                        hasCfg  = false;
                        cfgPath = "";
                        cfgName = "";
                    }
                    else
                    {
                        hasCfg  = true;
                        cfgPath = c;
                        cfgName = Path.GetFileName(c);
                    }
                    imod.hasCfg  = hasCfg;
                    imod.cfgPath = cfgPath;
                    imod.cfgName = cfgName;
                    nl.Add(imod);
                }
                vmod.Conf = nl;
                return(View["_page-system-conf", vmod]);
            };

            Post["/export/file/{path*}"] = x => {
                string path = x.path;
                ConfigEtc.Export(path);
                return(Response.AsJson("done"));
            };

            Get["/read/file/{path*}"] = x => {
                string path = x.path;
                string text = FileSystem.ReadFile(path.RemoveDriveLetter());
                return(Response.AsJson(text));
            };

            Post["/file"] = x => {
                string path    = this.Request.Form.FilePath;
                string content = this.Request.Form.FileContent;
                ConfigEtc.EditFile(path, content);
                return(Response.AsRedirect("/system"));
            };

            Post["/sysctl/{param}/{value}"] = x => {
                string param  = x.param;
                string value  = x.value;
                var    output = Sysctl.Config(param, value);
                return(Response.AsJson(output));
            };

            Get["/wizard"] = x => {
                dynamic vmod = new ExpandoObject();
                return(View["page-wizard", vmod]);
            };
        }