summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWouterTinus <wouter.tinus@gmail.com>2019-02-23 17:58:49 +0100
committerWouterTinus <wouter.tinus@gmail.com>2019-02-23 17:58:49 +0100
commit2e006d9a2238a86ca42f7f22521373d191365fab (patch)
tree8b1f5a6e8312e05f44532e6a0b1f11316ff5d2f0
parent6c7a4f557a8c074bc2fc59496e9e92760e732942 (diff)
downloadletsencrypt-win-simple-2e006d9a2238a86ca42f7f22521373d191365fab.zip
letsencrypt-win-simple-2e006d9a2238a86ca42f7f22521373d191365fab.tar.gz
letsencrypt-win-simple-2e006d9a2238a86ca42f7f22521373d191365fab.tar.bz2
Add default choices for the yes/no questions
-rw-r--r--src/main/Acme/AcmeClient.cs4
-rw-r--r--src/main/MainMenu.cs4
-rw-r--r--src/main/Plugins/InstallationPlugins/IISWeb/IISWebOptionsFactory.cs2
-rw-r--r--src/main/Plugins/Resolvers/InteractiveResolver.cs12
-rw-r--r--src/main/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs2
-rw-r--r--src/main/Plugins/ValidationPlugins/Http/HttpValidation.cs2
-rw-r--r--src/main/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs2
-rw-r--r--src/main/Renew.cs4
-rw-r--r--src/main/Services/InputService.cs27
-rw-r--r--src/main/Services/Interfaces/IInputService.cs2
-rw-r--r--src/main/Services/TaskSchedulerService.cs4
-rw-r--r--src/main/Wacs.cs6
12 files changed, 45 insertions, 26 deletions
diff --git a/src/main/Acme/AcmeClient.cs b/src/main/Acme/AcmeClient.cs
index 23fce7c..073fcfb 100644
--- a/src/main/Acme/AcmeClient.cs
+++ b/src/main/Acme/AcmeClient.cs
@@ -101,9 +101,9 @@ namespace PKISharp.WACS.Acme
var tosPath = Path.Combine(_settings.ConfigPath, filename);
File.WriteAllBytes(tosPath, content);
_input.Show($"Terms of service", tosPath);
- if (_input.PromptYesNo($"Open in default application?"))
+ if (_input.PromptYesNo($"Open in default application?", false))
Process.Start(tosPath);
- if (!_input.PromptYesNo($"Do you agree with the terms?"))
+ if (!_input.PromptYesNo($"Do you agree with the terms?", true))
return null;
}
account = await _client.CreateAccountAsync(contacts, termsOfServiceAgreed: true);
diff --git a/src/main/MainMenu.cs b/src/main/MainMenu.cs
index 37b9ca0..f63724a 100644
--- a/src/main/MainMenu.cs
+++ b/src/main/MainMenu.cs
@@ -127,7 +127,7 @@ namespace PKISharp.WACS
"Back");
if (renewal != null)
{
- if (_input.PromptYesNo($"Are you sure you want to revoke {renewal}?"))
+ if (_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))
{
@@ -153,7 +153,7 @@ namespace PKISharp.WACS
{
var renewals = _renewalService.Renewals;
_input.WritePagedList(renewals.Select(x => Choice.Create(x)));
- if (_input.PromptYesNo("Are you sure you want to cancel all of these?"))
+ if (_input.PromptYesNo("Are you sure you want to cancel all of these?", false))
{
_renewalService.Clear();
}
diff --git a/src/main/Plugins/InstallationPlugins/IISWeb/IISWebOptionsFactory.cs b/src/main/Plugins/InstallationPlugins/IISWeb/IISWebOptionsFactory.cs
index e3be6f6..93ab55c 100644
--- a/src/main/Plugins/InstallationPlugins/IISWeb/IISWebOptionsFactory.cs
+++ b/src/main/Plugins/InstallationPlugins/IISWeb/IISWebOptionsFactory.cs
@@ -32,7 +32,7 @@ namespace PKISharp.WACS.Plugins.InstallationPlugins
{
if (runLevel.HasFlag(RunLevel.Advanced))
{
- ask = inputService.PromptYesNo("Use different site for installation?");
+ ask = inputService.PromptYesNo("Use different site for installation?", false);
}
else
{
diff --git a/src/main/Plugins/Resolvers/InteractiveResolver.cs b/src/main/Plugins/Resolvers/InteractiveResolver.cs
index f069000..b1d7294 100644
--- a/src/main/Plugins/Resolvers/InteractiveResolver.cs
+++ b/src/main/Plugins/Resolvers/InteractiveResolver.cs
@@ -1,8 +1,10 @@
using Autofac;
using PKISharp.WACS.DomainObjects;
using PKISharp.WACS.Plugins.Base.Factories.Null;
+using PKISharp.WACS.Plugins.CsrPlugins;
using PKISharp.WACS.Plugins.InstallationPlugins;
using PKISharp.WACS.Plugins.Interfaces;
+using PKISharp.WACS.Plugins.StorePlugins;
using PKISharp.WACS.Plugins.ValidationPlugins.Http;
using PKISharp.WACS.Services;
using System.Collections.Generic;
@@ -60,7 +62,7 @@ namespace PKISharp.WACS.Plugins.Resolvers
Where(x => !(x is INull)).
Where(x => x.CanValidate(target)).
OrderBy(x => x.ChallengeType + x.Description),
- x => Choice.Create(x, description: $"[{x.ChallengeType}] {x.Description}"),
+ x => Choice.Create(x, description: $"[{x.ChallengeType}] {x.Description}", @default: x is SelfHostingOptionsFactory),
"Abort");
return ret ?? new NullValidationFactory();
}
@@ -93,7 +95,7 @@ namespace PKISharp.WACS.Plugins.Resolvers
_plugins.CsrPluginOptionsFactories(scope).
Where(x => !(x is INull)).
OrderBy(x => x.Description),
- x => Choice.Create(x, description: x.Description));
+ x => Choice.Create(x, description: x.Description, @default: x is RsaOptionsFactory));
return ret;
}
else
@@ -112,7 +114,7 @@ namespace PKISharp.WACS.Plugins.Resolvers
_plugins.StorePluginFactories(scope).
Where(x => !(x is INull)).
OrderBy(x => x.Description),
- x => Choice.Create(x, description: x.Description));
+ x => Choice.Create(x, description: x.Description, @default: x is CertificateStoreOptionsFactory));
return ret;
}
else
@@ -144,7 +146,7 @@ namespace PKISharp.WACS.Plugins.Resolvers
var installer = _input.ChooseFromList(
"Which installer should run for the certificate?",
filtered,
- x => Choice.Create(x, description: x.Description),
+ x => Choice.Create(x, description: x.Description, @default: x is IISWebOptionsFactory),
"Abort");
if (installer != null)
{
@@ -154,7 +156,7 @@ namespace PKISharp.WACS.Plugins.Resolvers
filtered = filtered.Where(x => !ret.Contains(x)).Where(x => !(x is INull)).OrderBy(x => x.Description);
if (filtered.Any())
{
- ask = _input.PromptYesNo("Would you like to add another installer step?");
+ ask = _input.PromptYesNo("Would you like to add another installer step?", false);
}
}
}
diff --git a/src/main/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs b/src/main/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs
index 34a6cb8..b2127d4 100644
--- a/src/main/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs
+++ b/src/main/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs
@@ -44,7 +44,7 @@ namespace PKISharp.WACS.Plugins.ValidationPlugins.Http
var ret = new FileSystemOptions(BaseAquire(target, arguments, inputService, runLevel));
if (target.IIS && _iisClient.HasWebSites && string.IsNullOrEmpty(ret.Path))
{
- if (inputService.PromptYesNo("Use different site for validation?"))
+ if (inputService.PromptYesNo("Use different site for validation?", false))
{
var site = inputService.ChooseFromList("Validation site, must receive requests for all hosts on port 80",
_iisClient.WebSites,
diff --git a/src/main/Plugins/ValidationPlugins/Http/HttpValidation.cs b/src/main/Plugins/ValidationPlugins/Http/HttpValidation.cs
index 66795f1..1ed7c41 100644
--- a/src/main/Plugins/ValidationPlugins/Http/HttpValidation.cs
+++ b/src/main/Plugins/ValidationPlugins/Http/HttpValidation.cs
@@ -82,7 +82,7 @@ namespace PKISharp.WACS.Plugins.ValidationPlugins
_log.Information("Answer should now be browsable at {answerUri}", _challenge.HttpResourceUrl);
if (_runLevel.HasFlag(RunLevel.Test) && _renewal.New)
{
- if (_input.PromptYesNo("[--test] Try in default browser?"))
+ if (_input.PromptYesNo("[--test] Try in default browser?", false))
{
Process.Start(_challenge.HttpResourceUrl);
_input.Wait();
diff --git a/src/main/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs b/src/main/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs
index 8ab167a..0101fd7 100644
--- a/src/main/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs
+++ b/src/main/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs
@@ -31,7 +31,7 @@ namespace PKISharp.WACS.Plugins.ValidationPlugins
}
return new TOptions {
Path = path,
- CopyWebConfig = target.IIS || input.PromptYesNo("Copy default web.config before validation?")
+ CopyWebConfig = target.IIS || input.PromptYesNo("Copy default web.config before validation?", false)
};
}
diff --git a/src/main/Renew.cs b/src/main/Renew.cs
index 33b2dfd..1791e6f 100644
--- a/src/main/Renew.cs
+++ b/src/main/Renew.cs
@@ -157,7 +157,7 @@ namespace PKISharp.WACS
}
// Early escape for testing validation only
- if (renewal.New && runLevel.HasFlag(RunLevel.Test) && !_input.PromptYesNo($"[--test] Do you want to install the certificate?"))
+ if (renewal.New && runLevel.HasFlag(RunLevel.Test) && !_input.PromptYesNo($"[--test] Do you want to install the certificate?", true))
{
return new RenewResult("User aborted");
}
@@ -222,7 +222,7 @@ namespace PKISharp.WACS
if (renewal.New && !_args.NoTaskScheduler)
{
- if (runLevel.HasFlag(RunLevel.Test) && !_input.PromptYesNo($"[--test] Do you want to automatically renew this certificate?"))
+ if (runLevel.HasFlag(RunLevel.Test) && !_input.PromptYesNo($"[--test] Do you want to automatically renew this certificate?", true))
{
// Early out for test runs
return new RenewResult("User aborted");
diff --git a/src/main/Services/InputService.cs b/src/main/Services/InputService.cs
index 15b159b..39bc36e 100644
--- a/src/main/Services/InputService.cs
+++ b/src/main/Services/InputService.cs
@@ -126,26 +126,39 @@ namespace PKISharp.WACS.Services
var inputStream = Console.OpenStandardInput(bufferSize);
Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, bufferSize));
+ var top = Console.CursorTop;
+ var left = Console.CursorLeft;
answer = Console.ReadLine();
- Console.WriteLine();
+
if (string.IsNullOrWhiteSpace(answer))
{
+ Console.SetCursorPosition(left, top);
+ Console.WriteLine("<Enter>");
+ Console.WriteLine();
return string.Empty;
}
else
{
+ Console.WriteLine();
return answer.Trim();
}
}
- public bool PromptYesNo(string message)
+ public bool PromptYesNo(string message, bool defaultChoice)
{
Validate(message);
CreateSpace();
Console.ForegroundColor = ConsoleColor.Green;
Console.Write($" {message} ");
Console.ForegroundColor = ConsoleColor.Yellow;
- Console.Write($"(y/n): ");
+ if (defaultChoice)
+ {
+ Console.Write($"(y*/n) ");
+ }
+ else
+ {
+ Console.Write($"(y/n*) ");
+ }
Console.ResetColor();
while (true)
{
@@ -153,11 +166,15 @@ namespace PKISharp.WACS.Services
switch (response.Key)
{
case ConsoleKey.Y:
- Console.WriteLine("- yes");
+ Console.WriteLine(" - yes");
Console.WriteLine();
return true;
case ConsoleKey.N:
- Console.WriteLine("- no");
+ Console.WriteLine(" - no");
+ Console.WriteLine();
+ return false;
+ case ConsoleKey.Enter:
+ Console.WriteLine($" - <Enter>");
Console.WriteLine();
return false;
}
diff --git a/src/main/Services/Interfaces/IInputService.cs b/src/main/Services/Interfaces/IInputService.cs
index 9690958..8e6e1e8 100644
--- a/src/main/Services/Interfaces/IInputService.cs
+++ b/src/main/Services/Interfaces/IInputService.cs
@@ -7,7 +7,7 @@ namespace PKISharp.WACS.Services
{
TResult ChooseFromList<TSource, TResult>(string what, IEnumerable<TSource> options, Func<TSource, Choice<TResult>> creator, string nullChoiceLabel = null);
TResult ChooseFromList<TResult>(string what, List<Choice<TResult>> choices);
- bool PromptYesNo(string message);
+ bool PromptYesNo(string message, bool defaultOption);
string ReadPassword(string what);
string RequestString(string what);
string RequestString(string[] what);
diff --git a/src/main/Services/TaskSchedulerService.cs b/src/main/Services/TaskSchedulerService.cs
index 59b95cc..e1f0a41 100644
--- a/src/main/Services/TaskSchedulerService.cs
+++ b/src/main/Services/TaskSchedulerService.cs
@@ -51,7 +51,7 @@ namespace PKISharp.WACS.Services
if (existingTask != null)
{
- if (!_runLevel.HasFlag(RunLevel.Advanced) || !_input.PromptYesNo($"Do you want to replace the existing task?"))
+ if (!_runLevel.HasFlag(RunLevel.Advanced) || !_input.PromptYesNo($"Do you want to replace the existing task?", false))
return;
_log.Information("Deleting existing task {taskName} from Windows Task Scheduler.", taskName);
@@ -104,7 +104,7 @@ namespace PKISharp.WACS.Services
{
if (!_options.UseDefaultTaskUser &&
_runLevel.HasFlag(RunLevel.Advanced) &&
- _input.PromptYesNo($"Do you want to specify the user the task will run as?"))
+ _input.PromptYesNo($"Do you want to specify the user the task will run as?", false))
{
// Ask for the login and password to allow the task to run
var username = _input.RequestString("Enter the username (Domain\\username)");
diff --git a/src/main/Wacs.cs b/src/main/Wacs.cs
index ddf1b48..7f76326 100644
--- a/src/main/Wacs.cs
+++ b/src/main/Wacs.cs
@@ -200,7 +200,7 @@ namespace PKISharp.WACS
{
if (_args.Test && !_args.CloseOnFinish)
{
- _args.CloseOnFinish = _input.PromptYesNo("[--test] Quit?");
+ _args.CloseOnFinish = _input.PromptYesNo("[--test] Quit?", false);
}
else
{
@@ -223,7 +223,7 @@ namespace PKISharp.WACS
var overwrite = false;
if (runLevel.HasFlag(RunLevel.Interactive))
{
- overwrite = _input.PromptYesNo($"A renewal with the FriendlyName {temp.LastFriendlyName} already exists, overwrite?");
+ overwrite = _input.PromptYesNo($"Renewal with FriendlyName {temp.LastFriendlyName} already exists, overwrite?", true);
}
else
{
@@ -267,7 +267,7 @@ namespace PKISharp.WACS
"Back");
if (renewal != null)
{
- if (_input.PromptYesNo($"Are you sure you want to cancel the renewal for {renewal}"))
+ if (_input.PromptYesNo($"Are you sure you want to cancel the renewal for {renewal}", false))
{
_renewalService.Cancel(renewal);
}