public static void DeleteNftRule(string guid) { var command = ConfigManagement.GetCommandsBundle().Where(_ => _.Guid == guid).Select(_ => _.Command).FirstOrDefault(); if (command == null || command.Length <= 0) { return; } var chain = command.Split(' ')[4]; var hook = command.Split(' ')[5]; var checkTables = Terminal.Terminal.Execute($"nft list table {chain} -a | grep \"{command}\""); if (checkTables.Length > 0) { var handle = checkTables.Split(' ').Last(); Terminal.Terminal.Execute($"nft delete rule {chain} {hook} handle {handle}"); } ConfigManagement.DeleteCommandsBundle(guid); }
public ConfModule() { this.RequiresAuthentication(); Post["/cfg/addvalue"] = x => { var tag = (string)Request.Form.Tag; var key = (string)Request.Form.Key; var value = (string)Request.Form.Value; if (key.Length > 0) { ConfigManagement.AddValuesBundle(tag, key, value); } else { ConfigManagement.AddValuesBundle(tag, value); } return(Response.AsRedirect("/")); }; Post["/cfg/delvalue"] = x => { var tag = (string)Request.Form.Tag; var key = (string)Request.Form.Key; var value = (string)Request.Form.Value; ConfigManagement.DeleteValuesBundle(tag, key, value); return(Response.AsRedirect("/")); }; Get["/cfg/tags"] = x => { var data = ConfigManagement.GetTagsBundleValue(); var map = SelectizerMapModel.MapRawTagOfValueBundle(data); return(Response.AsJson(map)); }; Post["/cfg/addcommand"] = x => { var command = (string)Request.Form.Command; if (command.Length > 0) { ConfigManagement.AddCommandsBundle(command); } return(Response.AsRedirect("/")); }; Post["/cfg/delcommand"] = x => { var guid = (string)Request.Form.Guid; ConfigManagement.DeleteCommandsBundle(guid); return(Response.AsRedirect("/")); }; Post["/cfg/enablecommand"] = x => { var guid = (string)Request.Form.Guid; ConfigManagement.EnableCommand(guid); return(Response.AsJson(true)); }; Post["/cfg/disablecommand"] = x => { var guid = (string)Request.Form.Guid; ConfigManagement.DisableCommand(guid); return(Response.AsJson(true)); }; Post["/cfg/launchcommand"] = x => { var guid = (string)Request.Form.Guid; ConfigManagement.LaunchCommand(guid); return(Response.AsRedirect("/")); }; Post["/cfg/reindex"] = x => { var guid = (string)Request.Form.Guid; var index = (string)Request.Form.Index; var guids = guid.Split(','); var indexes = index.Split(','); for (var i = 0; i < guids.Length; i++) { ConfigManagement.AssignIndexToCommandsBundle(guids[i], indexes[i]); } return(Response.AsRedirect("/")); }; Get["/cfg/getenabled"] = x => { var data = ConfigManagement.GetCommandsBundle().Where(_ => _.IsEnabled); return(Response.AsJson(data)); }; Get["/cfg/layouts"] = x => { var data = ConfigManagement.GetCommandsBundleLayout(); var map = SelectizerMapModel.MapRawCommandBundleLayout(data); return(Response.AsJson(map)); }; Post["/cfg/export"] = x => { ConfigManagement.Export.ExportConfigurationToFile(); return(Response.AsJson(true)); }; }
public static IEnumerable <ConfigManagement.CommandsBundle> GetNftCommandsBundle() { return(ConfigManagement.GetCommandsBundle().Where(_ => _.Command.StartsWith("nft"))); }
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]); }; }