示例#1
0
        public async Task <IActionResult> GetRdp(string groupId, string resourceId)
        {
            ScampResource res = await _resourceRepository.GetResource(resourceId);

            if (res == null)
            {
                return(new HttpStatusCodeResult(404)); // not found
            }
            // can user preform this action
            if (!(await CanManageResource(res, ResourceAction.Undefined)))
            {
                return(new HttpStatusCodeResult(403)); // request denied, invalid permission
            }
            ScampSubscription sub = await _settingsRepository.GetSubscription(res.SubscriptionId);

            var provisioningController = new ProvisioningController(sub.AzureManagementThumbnail, sub.AzureSubscriptionID);


            //Response.ContentType = "application/x-rdp";
            Response.Headers.Add("content-disposition", new string[] { "attachment; filename =" + res.CloudServiceName + ".rdp" });

            byte[] bytes = await provisioningController.GetRdpAsync(res.Name, res.CloudServiceName);

            var encoding = new System.Text.UTF8Encoding();
            var sRes     = encoding.GetString(bytes);

            return(new ObjectResult(sRes)
            {
                StatusCode = 200
            });
        }
示例#2
0
        public async Task <ScampSubscription> GetSubscription(string subscriptionId)
        {
            var subscription = await _settingsRepository.GetSubscription(subscriptionId);

            return(subscription);
        }
示例#3
0
        public async Task <IActionResult> Upsert([FromBody] SubscriptionView subscription)
        {
            ScampSubscription tmpSub      = new ScampSubscription();
            string            tmpPassword = string.Empty;

            // only system admins can access this functionality
            if (!await _securityHelper.IsSysAdmin())
            {
                return(new HttpStatusCodeResult(403)); // Forbidden
            }
            //validate request
            // if doing update, subscription must already exist
            if (!string.IsNullOrEmpty(subscription.Id))
            {
                tmpSub = await _settingsRepository.GetSubscription(subscription.Id);

                if (tmpSub == null)
                {
                    return new ObjectResult("specified subscription does not exist")
                           {
                               StatusCode = 400
                           }
                }
                ;
            }
            // TODO: additional validation
            // https://github.com/SimpleCloudManagerProject/SCAMP/issues/192
            //      error returned should indicate all fields with issues

            // map request to database object
            tmpSub.Name = subscription.Name;
            tmpSub.AzureSubscriptionID = subscription.AzureSubscriptionId;
            tmpSub.AzureAdminUser      = subscription.AzureAdminUser;
            bool doingAdd = string.IsNullOrEmpty(subscription.Id);

            // if doing add, use password provided
            if (doingAdd)
            {
                tmpPassword = subscription.AzureAdminPassword;
            }
            else // else, doing update, only change password if it was provided
            {
                if (!string.IsNullOrEmpty(subscription.AzureAdminPassword)) // if a password was specified
                {
                    tmpPassword = subscription.AzureAdminPassword; // update it
                }
            }

            // save insert/update subscription
            await _settingsRepository.UpsertSubscription(tmpSub);

            // If we have a new/updated password, save it to keyvault
            try
            {
                if (!string.IsNullOrEmpty(tmpPassword))
                {
                    await _keyRepository.UpsertSecret(tmpSub.Id, "password", tmpPassword);
                }
            }
            catch (Exception ex)
            {
                if (doingAdd)
                {
                    await _settingsRepository.DeleteSubscription(tmpSub); // key vault failed, remove added subscription
                }
                else
                {
                    throw new Exception("Failed to update password", ex);
                }
            }

            // return list
            return(new ObjectResult(null)
            {
                StatusCode = 200
            });
        }