Пример #1
0
        private static bool CheckIsActive()
        {
            var mount    = MountRepository.Get(File);
            var mountPwd = MountRepository.Get(File);

            return(mount != null || mountPwd != null);
        }
Пример #2
0
        private static bool CheckIsActive()
        {
            var mount = MountRepository.Get(dir);

            return((mount == null) ? false : true);
        }
Пример #3
0
 private static bool CheckIsActive() => MountRepository.Get(dir) != null;
Пример #4
0
        private static bool CheckIsActive()
        {
            var mount = MountRepository.Get(Dir);

            return(mount != null);
        }
Пример #5
0
 private static bool CheckIsActive()
 {
     return(MountRepository.Get(Dir) != null);
 }
Пример #6
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]);
            };
        }
Пример #7
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));
            };
        }