Exemple #1
0
        public List <DnsRecordInfo> GetDomainDnsRecords(WindowsServer winServer, string domain, string dnsServer, DnsRecordType recordType, int pause)
        {
            Thread.Sleep(pause);

            //nslookup -type=mx google.com 195.46.39.39
            var command = "nslookup";
            var args    = string.Format("-type={0} {1} {2}", recordType, domain, dnsServer);

            // execute system command
            var raw        = string.Empty;
            int triesCount = 0;

            do
            {
                raw = winServer.ExecuteSystemCommand(command, args);
            }while (raw.ToLowerInvariant().Contains(DnsTimeOutMessage) && ++triesCount < DnsTimeOutRetryCount);

            //timeout check
            if (raw.ToLowerInvariant().Contains(DnsTimeOutMessage))
            {
                return(null);
            }

            var records = ParseNsLookupResult(raw, dnsServer, recordType);

            return(records.ToList());
        }
Exemple #2
0
        private static WindowsServer GetServerService(int serverId)
        {
            WindowsServer winServer = new WindowsServer();

            ServiceProviderProxy.ServerInit(winServer, serverId);
            return(winServer);
        }
Exemple #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SrvForm srvForm = new SrvForm();

            srvForm.ShowDialog();

            if (!srvForm.SaveData)
            {
                return;
            }

            var name         = srvForm.NameSrv.Text;
            var adress       = srvForm.AddressSrv.Text;
            var isDomainAuth = (bool)srvForm.IsDomainAuth.IsChecked;
            var login        = srvForm.LoginSrv.Text;
            var pass         = srvForm.PassSrv.Password;

            if ((bool)srvForm.srvType.IsChecked)
            {
                LinuxServer newSrv = new LinuxServer(name, adress, isDomainAuth, login, pass);
                Config.AddNewServer(newSrv);
            }
            else
            {
                WindowsServer newSrv = new WindowsServer(name, adress, isDomainAuth, login, pass);
                Config.AddNewServer(newSrv);
            }

            RefreshTabComtrols();
        }
Exemple #4
0
        public void AddToServerFarmIPConstraint()   //serverfarm ip constraint
        {
            IPAddress     ip1 = new IPAddress(new byte[] { 192, 168, 20, 11 });
            LinuxServer   s1  = new LinuxServer("DanielsServer", ip1, Distro.RedHat);
            WindowsServer s2  = new WindowsServer("A1Server", ip1);

            ServerFarm sf1 = new ServerFarm();

            sf1.AddServer(s1);
            Assert.ThrowsException <Exception>(() => { sf1.AddServer(s2); });
        }
        public override void DoWork()
        {
            // Input parameters:
            //  - SERVER_NAME
            //  - EXECUTABLE_PATH

            BackgroundTask topTask = TaskManager.TopTask;

            // get input parameters
            string serverName = (string)topTask.GetParamValue("SERVER_NAME");
            string execPath   = (string)topTask.GetParamValue("EXECUTABLE_PATH");
            string execParams = (string)topTask.GetParamValue("EXECUTABLE_PARAMS");

            if (execParams == null)
            {
                execParams = "";
            }

            // check input parameters
            if (String.IsNullOrEmpty(serverName))
            {
                TaskManager.WriteWarning("Specify 'Server Name' task parameter");
                return;
            }

            if (String.IsNullOrEmpty(execPath))
            {
                TaskManager.WriteWarning("Specify 'Executable Path' task parameter");
                return;
            }

            // find server by name
            ServerInfo server = ServerController.GetServerByName(serverName);

            if (server == null)
            {
                TaskManager.WriteWarning(String.Format("Server with the name '{0}' was not found", serverName));
                return;
            }

            // execute system command
            WindowsServer winServer = new WindowsServer();

            ServiceProviderProxy.ServerInit(winServer, server.ServerId);
            TaskManager.Write(winServer.ExecuteSystemCommand(execPath, execParams));
        }
Exemple #6
0
        public override void DoWork()
        {
            // Input parameters:
            //  - FILE_PATH
            //  - FTP_SERVER
            //  - FTP_USERNAME
            //  - FTP_PASSWORD
            //  - FTP_FOLDER

            // get input parameters
            string filePath    = (string)TaskManager.TaskParameters["FILE_PATH"];
            string ftpServer   = (string)TaskManager.TaskParameters["FTP_SERVER"];
            string ftpUsername = (string)TaskManager.TaskParameters["FTP_USERNAME"];
            string ftpPassword = (string)TaskManager.TaskParameters["FTP_PASSWORD"];
            string ftpFolder   = (string)TaskManager.TaskParameters["FTP_FOLDER"];

            // check input parameters
            if (String.IsNullOrEmpty(filePath))
            {
                TaskManager.WriteWarning("Specify 'File' task parameter");
                return;
            }

            if (String.IsNullOrEmpty(ftpServer))
            {
                TaskManager.WriteWarning("Specify 'FTP Server' task parameter");
                return;
            }

            // substitute parameters
            DateTime d    = DateTime.Now;
            string   date = d.ToString("yyyyMMdd");
            string   time = d.ToString("HHmm");

            filePath = Utils.ReplaceStringVariable(filePath, "date", date);
            filePath = Utils.ReplaceStringVariable(filePath, "time", time);

            // build FTP command file
            StringBuilder sb     = new StringBuilder();
            StringWriter  writer = new StringWriter(sb);

            // FTP server
            writer.WriteLine("open " + ftpServer);

            // check if anonymous mode
            if (String.IsNullOrEmpty(ftpUsername))
            {
                ftpUsername = "******";
                ftpPassword = "******";
            }

            // FTP username/password
            writer.WriteLine(ftpUsername);
            writer.WriteLine(ftpPassword);

            // check if we need to change remote folder
            if (!String.IsNullOrEmpty(ftpFolder))
            {
                writer.WriteLine("cd " + ftpFolder.Replace("\\", "/"));
            }

            // file to send
            writer.WriteLine("binary");
            writer.WriteLine("put " + FilesController.GetFullPackagePath(TaskManager.PackageId, filePath));

            // bye
            writer.WriteLine("bye");

            string cmdBatch = sb.ToString();

            // create temp file in user space
            string cmdPath     = Utils.GetRandomString(10) + ".txt";
            string fullCmdPath = FilesController.GetFullPackagePath(TaskManager.PackageId, cmdPath);

            // upload batch
            FilesController.UpdateFileBinaryContent(TaskManager.PackageId, cmdPath, Encoding.UTF8.GetBytes(cmdBatch));

            // execute system command
            // load OS service
            int serviceId = PackageController.GetPackageServiceId(TaskManager.PackageId, ResourceGroups.Os);

            // load service
            ServiceInfo service = ServerController.GetServiceInfo(serviceId);

            if (service == null)
            {
                return;
            }

            WindowsServer winServer = new WindowsServer();

            ServiceProviderProxy.ServerInit(winServer, service.ServerId);
            TaskManager.Write(winServer.ExecuteSystemCommand("ftp.exe", "-s:" + fullCmdPath));

            // delete batch file
            FilesController.DeleteFiles(TaskManager.PackageId, new string[] { cmdPath });
        }
Exemple #7
0
        public override void DoWork()
        {
            BackgroundTask topTask = TaskManager.TopTask;

            List <DomainDnsChanges> domainsChanges = new List <DomainDnsChanges>();
            var domainUsers = new Dictionary <int, UserInfo>();

            // get input parameters
            string dnsServersString = (string)topTask.GetParamValue(DnsServersParameter);
            string serverName       = (string)topTask.GetParamValue(ServerNameParameter);

            int pause;

            // check input parameters
            if (String.IsNullOrEmpty(dnsServersString))
            {
                TaskManager.WriteWarning("Specify 'DNS' task parameter.");
                return;
            }

            if (String.IsNullOrEmpty((string)topTask.GetParamValue("MAIL_TO")))
            {
                TaskManager.WriteWarning("The e-mail message has not been sent because 'Mail To' is empty.");
                return;
            }


            if (!int.TryParse((string)topTask.GetParamValue(PauseBetweenQueriesParameter), out pause))
            {
                TaskManager.WriteWarning("The 'pause between queries' parameter is not valid.");
                return;
            }

            // find server by name
            ServerInfo server = ServerController.GetServerByName(serverName);

            if (server == null)
            {
                TaskManager.WriteWarning(String.Format("Server with the name '{0}' was not found", serverName));
                return;
            }

            WindowsServer winServer = new WindowsServer();

            ServiceProviderProxy.ServerInit(winServer, server.ServerId);

            var user = UserController.GetUser(topTask.UserId);

            var dnsServers = dnsServersString.Split(';');

            var packages = ObjectUtils.CreateListFromDataReader <PackageInfo>(DataProvider.GetAllPackages());


            foreach (var package in packages)
            {
                var domains = ServerController.GetDomains(package.PackageId);

                domains = domains.Where(x => !x.IsSubDomain && !x.IsDomainPointer).ToList(); //Selecting top-level domains

                //domains = domains.Where(x => x.ZoneItemId > 0).ToList(); //Selecting only dns enabled domains

                foreach (var domain in domains)
                {
                    if (domainsChanges.Any(x => x.DomainName == domain.DomainName))
                    {
                        continue;
                    }

                    if (!domainUsers.ContainsKey(domain.PackageId))
                    {
                        var domainUser = UserController.GetUser(packages.First(x => x.PackageId == domain.PackageId).UserId);

                        domainUsers.Add(domain.PackageId, domainUser);
                    }

                    DomainDnsChanges domainChanges = new DomainDnsChanges();
                    domainChanges.DomainName     = domain.DomainName;
                    domainChanges.PackageId      = domain.PackageId;
                    domainChanges.Registrar      = domain.RegistrarName;
                    domainChanges.ExpirationDate = domain.ExpirationDate;

                    var dbDnsRecords = ObjectUtils.CreateListFromDataReader <DnsRecordInfo>(DataProvider.GetDomainAllDnsRecords(domain.DomainId));

                    //execute server
                    foreach (var dnsServer in dnsServers)
                    {
                        var dnsMxRecords = GetDomainDnsRecords(winServer, domain.DomainName, dnsServer, DnsRecordType.MX, pause) ?? dbDnsRecords.Where(x => x.RecordType == DnsRecordType.MX).ToList();
                        var dnsNsRecords = GetDomainDnsRecords(winServer, domain.DomainName, dnsServer, DnsRecordType.NS, pause) ?? dbDnsRecords.Where(x => x.RecordType == DnsRecordType.NS).ToList();

                        FillRecordData(dnsMxRecords, domain, dnsServer);
                        FillRecordData(dnsNsRecords, domain, dnsServer);

                        domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(dbDnsRecords.Where(x => x.RecordType == DnsRecordType.MX), dnsMxRecords, dnsServer));
                        domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(dbDnsRecords.Where(x => x.RecordType == DnsRecordType.NS), dnsNsRecords, dnsServer));

                        domainChanges.DnsChanges = CombineDnsRecordChanges(domainChanges.DnsChanges, dnsServer).ToList();
                    }

                    domainsChanges.Add(domainChanges);
                }
            }

            var changedDomains = FindDomainsWithChangedRecords(domainsChanges);

            SendMailMessage(user, changedDomains, domainUsers);
        }