Пример #1
0
        public override async Task <FileSystemOptions?> Aquire(Target target, IInputService inputService, RunLevel runLevel)
        {
            // Choose alternative site for validation
            var ret = new FileSystemOptions(await BaseAquire(target, inputService));

            if (target.IIS &&
                _iisClient.HasWebSites &&
                string.IsNullOrEmpty(ret.Path) &&
                runLevel.HasFlag(RunLevel.Advanced))
            {
                var siteId = await ValidationSite().GetValue();

                if (siteId != null || await inputService.PromptYesNo("Use different site for validation?", false))
                {
                    var site = await inputService.ChooseOptional("Validation site, must receive requests for all hosts on port 80",
                                                                 _iisClient.Sites.Where(x => x.Type == IISSiteType.Web),
                                                                 x => Choice.Create <IIISSite?>(x, x.Name, x.Id.ToString(), @default: x.Id == siteId),
                                                                 "Automatic (target site)");

                    if (site != null)
                    {
                        ret.Path   = site.Path;
                        ret.SiteId = site.Id;
                    }
                }
            }
            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Revoke certificate
        /// </summary>
        private async Task RevokeCertificate()
        {
            var renewal = await _input.ChooseOptional(
                "Which certificate would you like to revoke?",
                _renewalStore.Renewals,
                x => Choice.Create <Renewal?>(x),
                "Back");

            if (renewal != null)
            {
                if (await _input.PromptYesNo($"Are you sure you want to revoke {renewal}? This should only be done in case of a security breach.", false))
                {
                    using var scope = _scopeBuilder.Execution(_container, renewal, RunLevel.Unattended);
                    var cs = scope.Resolve <ICertificateService>();
                    try
                    {
                        await cs.RevokeCertificate(renewal);

                        renewal.History.Add(new RenewResult("Certificate revoked"));
                    }
                    catch (Exception ex)
                    {
                        _exceptionHandler.HandleException(ex);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Remove renewal from the list of scheduled items
        /// </summary>
        internal async Task CancelRenewal(RunLevel runLevel)
        {
            if (runLevel.HasFlag(RunLevel.Unattended))
            {
                if (!_arguments.HasFilter())
                {
                    _log.Error("Specify which renewal to cancel using the parameter --id or --friendlyname.");
                    return;
                }
                var targets = _renewalStore.FindByArguments(
                    _arguments.MainArguments.Id,
                    _arguments.MainArguments.FriendlyName);
                if (targets.Count() == 0)
                {
                    _log.Error("No renewals matched.");
                    return;
                }
                foreach (var r in targets)
                {
                    _renewalStore.Cancel(r);
                }
            }
            else
            {
                var renewal = await _input.ChooseOptional(
                    "Which renewal would you like to cancel?",
                    _renewalStore.Renewals,
                    x => Choice.Create <Renewal?>(x),
                    "Back");

                if (renewal != null)
                {
                    if (await _input.PromptYesNo($"Are you sure you want to cancel the renewal for {renewal}", false))
                    {
                        _renewalStore.Cancel(renewal);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// List secrets currently in vault as choices to pick from
        /// </summary>
        /// <returns></returns>
        private async Task <string?> FindSecret()
        {
            var chosenKey = await _inputService.ChooseOptional(
                "Which vault secret do you want to use?",
                _secretService.ListKeys(),
                (key) => Choice.Create <string?>(key, description: FormatKey(key)),
                "Cancel");

            if (chosenKey == null)
            {
                return(null);
            }
            else
            {
                return(FormatKey(chosenKey));
            }
        }
Пример #5
0
        /// <summary>
        /// Allow user to choose a TargetPlugin
        /// </summary>
        /// <returns></returns>
        public override async Task <ITargetPluginOptionsFactory?> GetTargetPlugin(ILifetimeScope scope)
        {
            var options = _plugins.TargetPluginFactories(scope).
                          Where(x => !x.Hidden).
                          OrderBy(x => x.Order).
                          ThenBy(x => x.Description);

            var defaultType = typeof(IISOptionsFactory);

            if (!options.OfType <IISOptionsFactory>().Any(x => !x.Disabled.Item1))
            {
                defaultType = typeof(ManualOptionsFactory);
            }

            if (!_runLevel.HasFlag(RunLevel.Advanced))
            {
                return((ITargetPluginOptionsFactory)scope.Resolve(defaultType));
            }

            // List options for generating new certificates
            _input.Show(null, "Please specify how the list of domain names that will be included in the certificate " +
                        "should be determined. If you choose for one of the \"all bindings\" options, the list will automatically be " +
                        "updated for future renewals to reflect the bindings at that time.",
                        true);

            var ret = await _input.ChooseOptional(
                "How shall we determine the domain(s) to include in the certificate?",
                options,
                x => Choice.Create <ITargetPluginOptionsFactory?>(
                    x,
                    description: x.Description,
                    @default: x.GetType() == defaultType,
                    disabled: x.Disabled.Item1,
                    disabledReason: x.Disabled.Item2),
                "Abort");

            return(ret ?? new NullTargetFactory());
        }