Exemplo n.º 1
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));
            };
        }