Esempio n. 1
0
        public CCTableModule()
            : base("/cctable")
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.list = CCTableRepository.GetAll();
                return(View["_page-cctable", vmod]);
            };

            Post["/"] = x => {
                string tbl = (string)this.Request.Form.Alias;
                if (tbl != "")
                {
                    CCTableRepository.CreateTable(tbl);
                }
                return(Response.AsRedirect("/cctable"));
            };

            Post["/row"] = x => {
                string table        = (string)this.Request.Form.TableGuid;
                string tableName    = (string)this.Request.Form.TableName;
                string label        = (string)this.Request.Form.Label;
                string inputType    = (string)this.Request.Form.InputType.Value;
                string inputValue   = (string)this.Request.Form.InputLabel;
                string inputCommand = (string)this.Request.Form.InputCommand;
                string notes        = (string)this.Request.Form.Notes;
                CCTableRepository.CreateRow(table, tableName, label, inputType, inputValue, inputCommand, notes);

                string command       = this.Request.Form.CCTableCommand;
                string inputid       = "New" + tableName.UppercaseAllFirstLetters().RemoveWhiteSpace() + label.UppercaseAllFirstLetters().RemoveWhiteSpace();
                string inputlocation = "CCTable" + this.Request.Form.TableName;
                CommandDB.Create(inputid, command, command, inputlocation, notes);

                return(Response.AsRedirect("/cctable"));
            };

            Get["/delete/table/{guid}"] = x => {
                string guid = x.guid;
                CCTableRepository.DeleteTable(guid);
                return(Response.AsJson("CCTable deleted"));
            };
        }
Esempio n. 2
0
        public CcTableModule()
        {
            this.RequiresAuthentication();

            Get["/cctable/cctable"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.list = CCTableRepository.GetAll();
                return(View["_page-cctable", vmod]);
            };

            Post["/cctable/cctable"] = x => {
                var tbl     = (string)Request.Form.Alias;
                var context = (string)Request.Form.Context;
                var tblType = (string)Request.Form.TableType;
                if (tbl.RemoveWhiteSpace().Length > 0)
                {
                    CCTableRepository.CreateTable(tbl, tblType, context);
                }
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row"] = x => {
                var    tableGuid     = (string)Request.Form.TableGuid;
                var    tableName     = (string)Request.Form.TableName;
                var    label         = (string)Request.Form.Label;
                var    inputType     = (string)Request.Form.InputType.Value;
                var    inputLabel    = (string)Request.Form.InputLabel;
                var    notes         = (string)Request.Form.Notes;
                var    osi           = (string)Request.Form.FlagOSI.Value;
                var    func          = (string)Request.Form.FlagFunction.Value;
                var    vOsi          = CCTableRepository.GetOsiLevel(osi);
                var    vFunc         = CCTableRepository.GetCommandFunction(func);
                var    inputId       = "New" + tableName.UppercaseAllFirstLetters().RemoveWhiteSpace() + label.UppercaseAllFirstLetters().RemoveWhiteSpace();
                string inputLocation = "CCTable" + Request.Form.TableName;
                string command;
                var    commandGet = (string)Request.Form.InputCommand;
                switch (inputType)
                {
                case "hidden":
                    command = Request.Form.CCTableCommandNone;
                    CCTableRepository.CreateRowForDirectCommand(tableGuid, tableName, label, inputLabel, command, notes, vOsi, vFunc, inputId, inputLocation);
                    break;

                case "text":
                    command = Request.Form.CCTableCommandText;
                    CCTableRepository.CreateRowForTextInputCommand(tableGuid, tableName, label, inputLabel, command, commandGet, notes, vOsi, vFunc, inputId, inputLocation);
                    break;

                case "checkbox":
                    string commandTrue  = Request.Form.CCTableCommandBooleanTrue;
                    string commandFalse = Request.Form.CCTableCommandBooleanFalse;
                    CCTableRepository.CreateRowForBooleanPairCommand(tableGuid, tableName, label, inputLabel, commandTrue, commandFalse, notes, vOsi, vFunc, inputId, inputLocation);
                    break;
                }

                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row/dataview"] = x => {
                var table     = (string)Request.Form.TableGuid;
                var tableName = (string)Request.Form.TableName;
                var label     = (string)Request.Form.Label;

                var commandString = (string)Request.Form.Command;
                var resultString  = (string)Request.Form.Result;
                ConsoleLogger.Log(commandString);
                if (commandString != "")
                {
                    var thisResult = resultString == "" ? Terminal.Execute(commandString) : resultString;
                    CCTableRepository.CreateRowDataView(table, tableName, label, commandString, thisResult);
                }
                ConsoleLogger.Log(commandString);

                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row/mapdata"] = x => {
                var rowGuid    = (string)Request.Form.ItemGuid;
                var labelArray = (string)Request.Form.MapLabel;
                var indexArray = (string)Request.Form.MapLabelIndex;
                CCTableRepository.SaveMapData(rowGuid, labelArray, indexArray);
                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row/refresh"] = x => {
                var guid = (string)Request.Form.Guid;
                CCTableRepository.Refresh(guid);
                return(Response.AsJson(true));
            };

            Get["/cctable/delete/table/{guid}"] = x => {
                string guid = x.guid;
                CCTableRepository.DeleteTable(guid);
                return(Response.AsJson("CCTable deleted"));
            };

            Get["/cctable/delete/row/{guid}"] = x => {
                string guid = x.guid;
                CCTableRepository.DeleteTableRow(guid);
                return(Response.AsJson("CCTable Row deleted"));
            };

            Get["/cctable/edit/row/{guid}/{cmd*}"] = x => {
                string guid = x.guid;
                string cmd  = x.cmd;
                CCTableRepository.EditTableRow(guid, cmd);
                return(Response.AsJson("CCTable Row deleted"));
            };

            Post["/cctable/Launch"] = x => {
                var commandType  = (string)Request.Form.Type;
                var rowGuid      = (string)Request.Form.RowGuid;
                var newValue     = (string)Request.Form.NewValue;
                var boolSelected = (string)Request.Form.BoolSelected;

                var row = CCTableRepository.GetRow(rowGuid);

                switch (commandType)
                {
                case "direct":
                    Terminal.Execute(row.CommandDirect);
                    break;

                case "text":
                    Terminal.Execute(row.CommandSet.Replace("{Value}", newValue));
                    break;

                case "bool":
                    if (boolSelected == "true")
                    {
                        Terminal.Execute(row.CommandTrue);
                    }
                    else if (boolSelected == "false")
                    {
                        Terminal.Execute(row.CommandFalse);
                    }
                    else
                    {
                        Terminal.Execute("echo COMMAND NOT FOUND");
                    }
                    break;
                }

                return(Response.AsJson(true));
            };

            Post["/cctable/row/conf"] = x => {
                var table     = (string)Request.Form.TableGuid;
                var tableName = (string)Request.Form.TableName;
                var file      = (string)Request.Form.File;

                var type = file.EndsWith(".conf") ? CCTableFlags.ConfType.File : CCTableFlags.ConfType.Directory;
                if (file != "")
                {
                    CCTableRepository.CreateRowConf(table, tableName, file, type);
                }
                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Get["/cctable/conf/files"] = x => Response.AsJson(CCTableRepository.GetEtcConfs());

            Post["/cctable/update/conf"] = x => {
                var file = (string)Request.Form.FileName;
                var text = (string)Request.Form.FileText;
                CCTableRepository.UpdateConfFile(file, text);
                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/map/conf"] = x => {
                var  guid               = Guid.NewGuid().ToString();
                var  commentInput       = ((string)Request.Form.CharComment).ToCharArray();
                var  comment            = commentInput.Length > 0 ? commentInput[0] : ' ';
                var  filePath           = (string)Request.Form.FilePath;
                bool hasInclude         = Request.Form.PermitsInclude.HasValue;
                var  include            = (string)Request.Form.VerbInclude;
                bool hasSection         = Request.Form.PermitsSection.HasValue;
                var  sectionOpenInput   = ((string)Request.Form.CharSectionOpen).ToCharArray();
                var  sectionOpen        = sectionOpenInput.Length > 0 ? sectionOpenInput[0] : ' ';
                var  sectionCloseInput  = ((string)Request.Form.CharSectionClose).ToCharArray();
                var  sectionClose       = sectionCloseInput.Length > 0 ? sectionCloseInput[0] : ' ';
                var  dataSeparatorInput = ((string)Request.Form.CharKevValueSeparator).ToCharArray();
                var  dataSeparator      = dataSeparatorInput.Length > 0 ? dataSeparatorInput[0] : ' ';
                bool hasBlock           = Request.Form.PermitsBlock.HasValue;
                var  blockOpenInput     = ((string)Request.Form.CharBlockOpen).ToCharArray();
                var  blockOpen          = blockOpenInput.Length > 0 ? blockOpenInput[0] : ' ';
                var  blockCloseInput    = ((string)Request.Form.CharBlockClose).ToCharArray();
                var  blockClose         = blockCloseInput.Length > 0 ? blockCloseInput[0] : ' ';
                var  endOfLineInput     = ((string)Request.Form.CharEndOfLine).ToCharArray();
                var  endOfLine          = endOfLineInput.Length > 0 ? endOfLineInput[0] : '\n';

                CCTableConf.Mapping.Repository.Create(guid, filePath, comment, hasInclude, include, hasSection, sectionOpen, sectionClose, dataSeparator, hasBlock, blockOpen, blockClose, endOfLine);

                var number  = (string)Request.Form.LineNumber;
                var numbers = number.Split(new[] { "," }, StringSplitOptions.None).ToIntArray();
                var type    = (string)Request.Form.LineType;
                var types   = type.Split(new[] { "," }, StringSplitOptions.None).ToArray();
                //linee e typi dovrebbero essere uguali
                if (numbers.Length == types.Length)
                {
                    var l = (numbers.Length + types.Length) / 2;
                    for (var i = 0; i < l; i++)
                    {
                        var ti = CCTableConf.Mapping.Repository.ConvertToDataType(types[i]);
                        CCTableConf.Mapping.Repository.AddLine(guid, numbers[i], ti);
                    }
                }

                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };
        }
Esempio n. 3
0
        public HomeModule()
        {
            this.RequiresAuthentication();
            Before += x => {
                if (CCTableRepository.GetByContext(CctableContextName) == null)
                {
                    CCTableRepository.CreateTable("System Configuration", "4", CctableContextName);
                }
                return(null);
            };

            Get["/"] = x => {
                dynamic viewModel = new ExpandoObject();

                viewModel.AntdContext = new[] {
                    "Info",
                    "Config",
                    "Network",
                    "DnsClient",
                    "Firewall",
                    "DnsServer",
                    "Proxy",
                    "Storage",
                    "Mount",
                    "Rsync",
                    "Users",
                    "Samba",
                };

                viewModel.Meminfo = Meminfo.GetMappedModel();
                if (SystemInfo.Get() == null)
                {
                    viewModel.VersionOS  = "";
                    viewModel.VersionAOS = "";
                }
                else
                {
                    viewModel.VersionOS  = SystemInfo.Get().VersionOs;
                    viewModel.VersionAOS = SystemInfo.Get().VersionAos;
                }

                viewModel.ActiveKernel               = Terminal.Execute("ls -la /mnt/cdrom/Kernel | grep active | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.RecoveryKernel             = Terminal.Execute("ls -la /mnt/cdrom/Kernel | grep recovery | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.ActiveSystem               = Terminal.Execute("ls -la /mnt/cdrom/System | grep active | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.RecoverySystem             = Terminal.Execute("ls -la /mnt/cdrom/System | grep recovery | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.Cpuinfo                    = Cpuinfo.Get();
                viewModel.NetworkPhysicalIf          = NetworkInterface.Physical;
                viewModel.NetworkVirtualIf           = NetworkInterface.Virtual;
                viewModel.NetworkBondIf              = NetworkInterface.Bond;
                viewModel.NetworkBridgeIf            = NetworkInterface.Bridge;
                viewModel.FirewallCommands           = NfTables.GetNftCommandsBundle();
                viewModel.FirewallMacAddressEnabled  = MacAddressDiscovery.GetEnabled();
                viewModel.FirewallMacAddressDisabled = MacAddressDiscovery.GetDisabled();
                viewModel.FirewallMacAddressNew      = MacAddressDiscovery.GetNew();
                viewModel.DhcpdStatus                = antdlib.Svcs.Dhcp.DhcpConfig.IsActive;
                var dhcpdModel = antdlib.Svcs.Dhcp.DhcpConfig.MapFile.Get();
                if (dhcpdModel != null)
                {
                    viewModel.DhcpdGetGlobal        = dhcpdModel.DhcpGlobal;
                    viewModel.DhcpdGetPrefix6       = dhcpdModel.DhcpPrefix6;
                    viewModel.DhcpdGetRange         = dhcpdModel.DhcpRange;
                    viewModel.DhcpdGetRange6        = dhcpdModel.DhcpRange6;
                    viewModel.DhcpdGetKeys          = dhcpdModel.DhcpKey;
                    viewModel.DhcpdGetSubnet        = dhcpdModel.DhcpSubnet;
                    viewModel.DhcpdGetSubnet6       = dhcpdModel.DhcpSubnet6;
                    viewModel.DhcpdGetHost          = dhcpdModel.DhcpHost;
                    viewModel.DhcpdGetFailover      = dhcpdModel.DhcpFailover;
                    viewModel.DhcpdGetSharedNetwork = dhcpdModel.DhcpSharedNetwork;
                    viewModel.DhcpdGetGroup         = dhcpdModel.DhcpGroup;
                    viewModel.DhcpdGetClass         = dhcpdModel.DhcpClass;
                    viewModel.DhcpdGetSubclass      = dhcpdModel.DhcpSubclass;
                    viewModel.DhcpdGetLogging       = dhcpdModel.DhcpLogging;
                }
                //viewModel.SambaStatus = antdlib.Svcs.Samba.SambaConfig.IsActive;
                //viewModel.SambaStructure = antdlib.Svcs.Samba.SambaConfig.SimpleStructure;
                //var sambaModel = antdlib.Svcs.Samba.SambaConfig.MapFile.Get();
                //if (sambaModel != null) {
                //    viewModel.SambaGetData = sambaModel.Data;
                //    viewModel.SambaGetShare = sambaModel.Share;
                //}

                viewModel.Mounts           = MountRepository.Get();
                viewModel.RsyncDirectories = Rsync.GetAll();
                viewModel.RsyncOptions     = new List <Tuple <string, string> > {
                    new Tuple <string, string>("--checksum", "skip based on checksum"),
                    new Tuple <string, string>("--archive", "archive mode"),
                    new Tuple <string, string>("--recursive", "recurse into directories"),
                    new Tuple <string, string>("--update", "skip files that are newer on the receiver"),
                    new Tuple <string, string>("--links", "copy symlinks as symlinks"),
                    new Tuple <string, string>("--copy-links", "transform symlink into referent file/dir"),
                    new Tuple <string, string>("--copy-dirlinks", "transform symlink to dir into referent dir"),
                    new Tuple <string, string>("--keep-dirlinks", "treat symlinked dir on receiver as dir"),
                    new Tuple <string, string>("--hard-links", "preserve hard links"),
                    new Tuple <string, string>("--hard-links", "preserve hard links"),
                    new Tuple <string, string>("--hard-links", "preserve hard links"),
                    new Tuple <string, string>("--perms", "preserve permissions"),
                    new Tuple <string, string>("--executability", "preserve executability"),
                    new Tuple <string, string>("--acls", "preserve ACLs"),
                    new Tuple <string, string>("--xattrs", "preserve extended attributes"),
                    new Tuple <string, string>("--owner", "preserve owner"),
                    new Tuple <string, string>("--group", "preserve group"),
                    new Tuple <string, string>("--times", "preserve modification times")
                };

                viewModel.UserEntities = UserEntity.Repository.GetAll();

                //todo check next parameters
                viewModel.SSHPort    = "22";
                viewModel.AuthStatus = ApplicationSetting.TwoFactorAuth();

                viewModel.CCTableContext = CctableContextName;
                var table = CCTableRepository.GetByContext2(CctableContextName);
                viewModel.CommandDirect = table.Content.Where(_ => _.CommandType == CCTableCommandType.Direct);
                viewModel.CommandText   = table.Content.Where(_ => _.CommandType == CCTableCommandType.TextInput);
                viewModel.CommandBool   = table.Content.Where(_ => _.CommandType == CCTableCommandType.BooleanPair);
                return(View["antd/page-antd", viewModel]);
            };

            Get["/log"] = x => {
                dynamic viewModel = new ExpandoObject();
                viewModel.AntdContext = new[] {
                    "AntdLog",
                    "SystemLog",
                    "LogReport",
                };

                viewModel.LOGS       = Logger.GetAll();
                viewModel.LogReports = Journalctl.Report.Get();
                return(View["antd/page-log", viewModel]);
            };

            Get["/ca"] = x => {
                dynamic viewModel = new ExpandoObject();
                viewModel.AntdContext = new[] {
                    "Manage",
                };

                viewModel.SslStatus       = "Enabled";
                viewModel.SslStatusAction = "Disable";
                if (ApplicationSetting.Ssl() == "no")
                {
                    viewModel.SslStatus       = "Disabled";
                    viewModel.SslStatusAction = "Enable";
                }
                viewModel.CertificatePath = ApplicationSetting.CertificatePath();
                viewModel.CaStatus        = "Enabled";
                if (ApplicationSetting.CertificateAuthority() == "no")
                {
                    viewModel.CaStatus = "Disabled";
                }
                viewModel.CaIsActive   = CertificateAuthority.IsActive;
                viewModel.Certificates = CertificateRepository.GetAll();

                return(View["antd/page-ca", viewModel]);
            };

            Get["/cfg"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.ValueBundle           = ConfigManagement.GetValuesBundle();
                vmod.EnabledCommandBundle  = ConfigManagement.GetCommandsBundle().Where(_ => _.IsEnabled).OrderBy(_ => _.Index);
                vmod.DisabledCommandBundle = ConfigManagement.GetCommandsBundle().Where(_ => _.IsEnabled == false).OrderBy(_ => _.Index);
                return(View["antd/page-cfg", vmod]);
            };
        }