コード例 #1
0
        public void UploadFile(Uri fileUrl, Stream s)
        {
            var filePath = fileUrl.AbsolutePath;

            // We need to strip off any leading '/' in the path or
            // else it creates a path with an empty leading segment
            if (filePath.StartsWith("/"))
            {
                filePath = filePath.Substring(1);
            }

            var s3 = new Amazon.S3.AmazonS3Client(
                AccessKeyId, SecretAccessKey, RegionEndpoint);

            var s3Requ = new Amazon.S3.Model.PutObjectRequest
            {
                BucketName      = BucketName,
                Key             = filePath,
                InputStream     = s,
                AutoCloseStream = false,
            };
            var s3Resp = s3.PutObject(s3Requ);

            if (DnsProvider != null)
            {
                var hostname = fileUrl.Host;
                DnsProvider.EditCnameRecord(hostname, DnsCnameTarget);
            }
            else
            {
                // TODO:  do nothing for now
                // Throw Exception???
            }
        }
コード例 #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));
            }
        }
コード例 #3
0
        public static void DeleteSubdomainForService(DnsProvider dnsProvider, Service service)
        {
            var zone       = dnsProvider.GetZone(service.Variables["SD-ZoneId"].ToString(), ZoneSearchType.Id);
            var domainName = Globals.DomainParser.Get(service.Variables["SD-FullSubDomain"].ToString());
            var removed    = dnsProvider.RemoveZone(zone, domainName.SubDomain);

            if (removed)
            {
                using (var securityBypass = new SecurityBypass(service))
                {
                    service.Variables.RemoveValue("SD-FullSubDomain");
                    service.Variables.RemoveValue("SD-ZoneId");
                    service.Variables.RemoveValue("SD-DnsProvider");
                    service.Save();
                }

                return;
            }

            throw new SubdomainException($"Failed to delete <strong>{domainName.Hostname}</strong> subdomain.");
        }
コード例 #4
0
        public static void CreateSubdomainForService(DnsProvider dnsProvider, Service service, string subdomain,
                                                     string baseDomain)
        {
            subdomain = ParseSubdomain(subdomain);
            if (IsIllegal(subdomain))
            {
                throw new SubdomainException($"<strong>Illegal Subdomain - {subdomain}</strong>");
            }

            if (!dnsProvider.ZoneExists(baseDomain, ZoneSearchType.Id))
            {
                throw new SubdomainException($"<strong>Invalid Zone</strong>");
            }

            var zone = dnsProvider.GetZone(baseDomain, ZoneSearchType.Id);

            if (!dnsProvider.SubdomainAvailable(zone, subdomain))
            {
                throw new SubdomainException($"<strong>{subdomain}.{zone.Name}</strong> is already taken!");
            }

            var created = dnsProvider.AddZone(zone, subdomain, service.PublicIpAddress);

            if (created)
            {
                using (var securityBypass = new SecurityBypass(service))
                {
                    service.Variables["SD-FullSubDomain"] = $"{subdomain}.{zone.Name}";
                    service.Variables["SD-ZoneId"]        = $"{zone.Id}";
                    service.Variables["SD-DnsProvider"]   = dnsProvider.DnsProviderType.DnsProviderId;
                    service.Save();
                }

                return;
            }

            throw new SubdomainException($"Failed to create <strong>{subdomain}.{zone.Name}</strong> subdomain.");
        }