Example #1
0
        private CommandResponse AfterMove(Service service)
        {
            if (_configuration.AfterServiceMoveAction == AfterServiceAction.DoNothing)
            {
                return(new CommandResponse(Globals.ModuleId, "Doing nothing.", ReturnStatus.SafeError));
            }

            var domainName  = Globals.DomainParser.Get(service.Variables["SD-FullSubDomain"].ToString());
            var dnsProvider = new DnsProviderType(int.Parse(service.Variables["SD-DnsProvider"].ToString()))
                              .DnsProvider;
            var zoneExists = dnsProvider.ZoneExists(domainName.RegistrableDomain, ZoneSearchType.Name);

            if (!zoneExists)
            {
                return(new CommandResponse(Globals.ModuleId, "Zone does not exist", ReturnStatus.SafeError));
            }

            var dnsZone = dnsProvider.GetZone(domainName.RegistrableDomain, ZoneSearchType.Name);

            switch (_configuration.AfterServiceMoveAction)
            {
            case AfterServiceAction.DeleteSubDomain:
                SubdomainHelper.DeleteSubdomainForService(dnsProvider, service);
                break;

            case AfterServiceAction.SetSubDomainToNewIpAddress:
                SubdomainHelper.DeleteSubdomainForService(dnsProvider, service);
                SubdomainHelper.CreateSubdomainForService(dnsProvider, service, domainName.SubDomain, dnsZone.Id);
                break;
            }

            return(new CommandResponse(Globals.ModuleId, "Successfully reset subdomain",
                                       ReturnStatus.Ok));
        }
Example #2
0
        public ActionResult Create(int id, string subdomain, string baseDomain)
        {
            var service = new Service(id);

            try
            {
                var generalConfiguration = new DatabaseConfiguration <GeneralConfiguration>(Globals.ModuleId, "GeneralConfiguration").GetConfiguration();
                var dnsProvider          = DnsProvider.GetDnsProviderFromBaseDomain(baseDomain, ZoneSearchType.Id);
                subdomain = $"{generalConfiguration.Prefix}{subdomain}{generalConfiguration.Postfix}";
                subdomain = Alexr03.Common.TCAdmin.Misc.Strings.VariableReplacement.ReplaceVariables(subdomain, service, TCAdmin.SDK.Session.GetCurrentUser());
                SubdomainHelper.CreateSubdomainForService(dnsProvider, service, subdomain, baseDomain);
                var dnsZone = dnsProvider.GetZone(baseDomain, ZoneSearchType.Id);
                return(this.SendSuccess($"Successfully created <strong>{subdomain}.{dnsZone.Name}</strong> subdomain."));
            }
            catch (SubdomainException subdomainException)
            {
                return(this.SendException(subdomainException));
            }
        }
Example #3
0
        public ActionResult Delete(int id)
        {
            var service = new Service(id);

            try
            {
                if (!service.Variables.HasValueAndSet("SD-FullSubDomain") || !service.Variables.HasValueAndSet("SD-DnsProvider"))
                {
                    return(this.SendError($"{service.GameShortNameAndConnectionInfo} does not have a subdomain set."));
                }
                var domain      = Globals.DomainParser.Get(service.Variables["SD-FullSubDomain"].ToString());
                var dnsProvider = new DnsProviderType(int.Parse(service.Variables["SD-DnsProvider"].ToString())).DnsProvider;
                SubdomainHelper.DeleteSubdomainForService(dnsProvider, service);
                return(this.SendSuccess($"Successfully deleted <strong>{domain.Hostname}</strong> subdomain."));
            }
            catch (SubdomainException subdomainException)
            {
                return(this.SendException(subdomainException));
            }
            catch (Exception exception)
            {
                return(this.SendException(exception));
            }
        }