Ejemplo n.º 1
0
        public FirewallModule()
        {
            this.RequiresAuthentication();
            Post["/firewall/addrule"] = x => {
                var command = (string)Request.Form.Command;
                var rule    = (string)Request.Form.Rule;
                NfTables.AddNftRule(command, rule);
                return(Response.AsRedirect("/"));
            };

            Post["/firewall/stoprule"] = x => {
                NfTables.DeleteNftRule((string)Request.Form.Guid);
                return(Response.AsRedirect("/"));
            };

            Get["/firewall/checkdefault"] = x => Response.AsJson(FirewallLists.GetAll().Count());

            Get["/firewall/getrule/{table}/{type}/{hook}"] = x => JsonConvert.SerializeObject(FirewallLists.GetForRule((string)x.table, (string)x.type, (string)x.hook));

            Get["/firewall/getruleset/{table}/{type}/{hook}"] = x => JsonConvert.SerializeObject(FirewallLists.GetRuleSet((string)x.table, (string)x.type, (string)x.hook));

            Post["/firewall/add/list"] = x => {
                var guid  = Guid.NewGuid().ToString();
                var table = (string)Request.Form.Table;
                var type  = (string)Request.Form.Type;
                var hook  = (string)Request.Form.Hook;
                var label = (string)Request.Form.Label;
                FirewallLists.AddList(guid, table, type, hook, label);
                var values = (string)Request.Form.Elements;
                if (values.Length <= 0)
                {
                    return(Response.AsRedirect("/"));
                }
                var valueList = values.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                FirewallLists.AddValueToList(guid, valueList);
                return(Response.AsRedirect("/"));
            };

            Post["/firewall/add/value"] = x => {
                var guid   = (string)Request.Form.Guid;
                var values = (string)Request.Form.Elements;
                if (values.Length <= 0)
                {
                    return(Response.AsJson(true));
                }
                var valueList = values.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                FirewallLists.AddValueToList(guid, valueList);
                return(Response.AsJson(true));
            };

            Post["/firewall/conf/export"] = x => {
                NfTables.Export.ExportNewFirewallConfiguration();
                return(Response.AsJson(true));
            };

            Post["/firewall/conf/apply"] = x => {
                NfTables.Export.ApplyConfiguration();
                return(Response.AsJson(true));
            };

            Post["/firewall/discover/macadd"] = x => {
                MacAddressDiscovery.Discover();
                return(Response.AsJson(true));
            };

            Post["/firewall/enable/macadd"] = x => {
                var guid = (string)Request.Form.Guid;
                MacAddressDiscovery.Unlock(guid);
                return(Response.AsJson(true));
            };

            Post["/firewall/disable/macadd"] = x => {
                var guid = (string)Request.Form.Guid;
                MacAddressDiscovery.Block(guid);
                return(Response.AsJson(true));
            };
        }
Ejemplo n.º 2
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]);
            };
        }