Ejemplo n.º 1
0
        public StorageModule()
        {
            this.RequiresAuthentication();

            Get["/storage"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.VolumesInfo    = Volumes.BlocksFromDd();
                vmod.IsOsRemovable  = InstallCheck.IsOsRemovable;
                vmod.Mounts         = antdlib.MountPoint.MountRepository.Get();
                vmod.CurrentContext = Request.Path;
                vmod.CCTable        = CCTableRepository.GetAllByContext(Request.Path);
                vmod.Count          = CCTableRepository.GetAllByContext(Request.Path).ToArray().Length;
                return(View["_page-storage", vmod]);
            };

            Get["/storage/reload/volumes"] = x => {
                Volumes.PopulateBlocks();
                return(Response.AsJson(true));
            };

            Post["/storage/install"] = x => {
                new InstallOperativeSystem((string)Request.Form.DiskName).SetDiskAndInstall();
                return(Response.AsJson(true));
            };

            Post["/rsync/add"] = x => {
                var source      = (string)Request.Form.Source;
                var destination = (string)Request.Form.Destination;
                var options     = (string)Request.Form.Options;
                var type        = (string)Request.Form.Type.Value;
                Rsync.Create(source, destination, options, type);
                return(Response.AsRedirect("/"));
            };
        }
Ejemplo n.º 2
0
 public void StartWatching()
 {
     try {
         var paths = Rsync.GetDirectoriesToWatch();
         foreach (var path in paths)
         {
             if (Directory.Exists(path) || File.Exists(path))
             {
                 var watcher = new FileSystemWatcher(path)
                 {
                     NotifyFilter =
                         NotifyFilters.LastAccess |
                         NotifyFilters.LastWrite |
                         NotifyFilters.FileName |
                         NotifyFilters.DirectoryName,
                     IncludeSubdirectories = true,
                 };
                 watcher.Changed            += OnChanged;
                 watcher.Created            += OnChanged;
                 watcher.Deleted            += OnChanged;
                 watcher.Renamed            += OnRenamed;
                 watcher.EnableRaisingEvents = true;
             }
             else
             {
                 throw new Exception($"directory Watcher: {path}");
             }
         }
     }
     catch (Exception ex) {
         ConsoleLogger.Log(ex.Message);
     }
 }
Ejemplo n.º 3
0
 private static void OnRenamed(object source, RenamedEventArgs e)
 {
     Rsync.SyncDirectories(e.FullPath);
     ConsoleLogger.Log($"directory Watcher: {e.OldName} renamed to {e.Name}");
 }
Ejemplo n.º 4
0
 private static void OnChanged(object source, FileSystemEventArgs e)
 {
     Rsync.SyncDirectories(e.FullPath);
     ConsoleLogger.Log($"directory Watcher: {e.FullPath} {e.ChangeType}");
 }
Ejemplo n.º 5
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]);
            };
        }