Exemple #1
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]);
            };
        }
Exemple #2
0
        public SystemModule()
        {
            this.RequiresAuthentication();

            Post["/system/cctable"] = x => {
                var    label         = (string)Request.Form.Label;
                var    inputLabel    = (string)Request.Form.InputLabel;
                var    notes         = (string)Request.Form.Notes;
                var    inputId       = "New" + CctableContextName.UppercaseAllFirstLetters().RemoveWhiteSpace() + label.UppercaseAllFirstLetters().RemoveWhiteSpace();
                string inputLocation = "CCTable" + Request.Form.TableName;
                switch ((string)Request.Form.InputType.Value)
                {
                case "hidden":
                    var directCommand = (string)Request.Form.CommandDirect;
                    CCTableRepository.New.CreateRowForDirectCommand(CctableContextName, label, inputLabel, directCommand,
                                                                    notes, inputId, inputLocation);
                    break;

                case "text":
                    var setCommand = (string)Request.Form.CommandSet;
                    var getCommand = (string)Request.Form.CommandGet;
                    CCTableRepository.New.CreateRowForTextInputCommand(CctableContextName, label, inputLabel, setCommand,
                                                                       getCommand, notes, inputId, inputLocation);
                    break;

                case "checkbox":
                    var enableCommand  = (string)Request.Form.CommandTrue;
                    var disableCommand = (string)Request.Form.CommandFalse;
                    CCTableRepository.New.CreateRowForBooleanPairCommand(CctableContextName, label, inputLabel,
                                                                         enableCommand, disableCommand, notes, inputId, inputLocation);
                    break;
                }
                return(Response.AsRedirect("/"));
            };

            Get["/system/auth/disable"] = x => {
                ApplicationSetting.DisableTwoFactorAuth();
                return(Response.AsJson(true));
            };

            Get["/system/auth/enable"] = x => {
                ApplicationSetting.EnableTwoFactorAuth();
                return(Response.AsJson(true));
            };

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

            Post["/system/mount/unit"] = x => {
                var    guid       = Request.Form.Guid;
                string unit       = Request.Form.Unit;
                var    unitsSplit = unit.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                if (unitsSplit.Length > 0)
                {
                    MountRepository.AddUnit(guid, unitsSplit);
                }
                return(Response.AsRedirect("/"));
            };

            Delete["/system/mount/unit"] = x => {
                var guid = Request.Form.Guid;
                var unit = Request.Form.Unit;
                MountRepository.RemoveUnit(guid, unit);
                return(Response.AsJson(true));
            };

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

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

            Post["/system/import/info"] = x => {
                SystemInfo.Import();
                return(Response.AsJson(true));
            };
        }