diff options
author | WouterTinus <wouter.tinus@gmail.com> | 2019-09-07 01:36:12 +0200 |
---|---|---|
committer | WouterTinus <wouter.tinus@gmail.com> | 2019-09-07 01:36:12 +0200 |
commit | 7673fa357a81444cf6c216267dfab4e76684ba5c (patch) | |
tree | 73c0bd36e5b6261cd89a168c2a099f6556c59f4d /src/main.lib/Plugins/ValidationPlugins/Http/FileSystem | |
parent | 42aa0faa4de6ea4184cfe1a5830508777418b11a (diff) | |
download | letsencrypt-win-simple-7673fa357a81444cf6c216267dfab4e76684ba5c.zip letsencrypt-win-simple-7673fa357a81444cf6c216267dfab4e76684ba5c.tar.gz letsencrypt-win-simple-7673fa357a81444cf6c216267dfab4e76684ba5c.tar.bz2 |
move plugins & re-implement WebDav
Diffstat (limited to 'src/main.lib/Plugins/ValidationPlugins/Http/FileSystem')
5 files changed, 222 insertions, 0 deletions
diff --git a/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystem.cs b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystem.cs new file mode 100644 index 0000000..1301f5b --- /dev/null +++ b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystem.cs @@ -0,0 +1,87 @@ +using PKISharp.WACS.Clients.IIS; +using PKISharp.WACS.Extensions; +using System; +using System.IO; +using System.Linq; + +namespace PKISharp.WACS.Plugins.ValidationPlugins.Http +{ + internal class FileSystem : HttpValidation<FileSystemOptions, FileSystem> + { + protected IIISClient _iisClient; + + public FileSystem(FileSystemOptions options, IIISClient iisClient, RunLevel runLevel, HttpValidationParameters pars) : base(options, runLevel, pars) + { + _iisClient = iisClient; + } + + protected override void DeleteFile(string path) + { + var fi = new FileInfo(path); + if (fi.Exists) + { + _log.Verbose("Deleting file {path}", path); + fi.Delete(); + } + else + { + _log.Warning("File {path} already deleted", path); + } + } + + protected override void DeleteFolder(string path) + { + var di = new DirectoryInfo(path); + if (di.Exists) + { + _log.Verbose("Deleting folder {path}", path); + di.Delete(); + } + else + { + _log.Warning("Folder {path} already deleted", path); + } + } + + protected override bool IsEmpty(string path) + { + return !(new DirectoryInfo(path)).GetFileSystemInfos().Any(); + } + + protected override void WriteFile(string path, string content) + { + var fi = new FileInfo(path); + if (!fi.Directory.Exists) + { + fi.Directory.Create(); + } + _log.Verbose("Writing file to {path}", path); + File.WriteAllText(path, content); + } + + /// <summary> + /// Update webroot + /// </summary> + /// <param name="scheduled"></param> + protected override void Refresh() + { + if (string.IsNullOrEmpty(_options.Path)) + { + // Update web root path + var siteId = _options.SiteId ?? _targetPart.SiteId; + if (siteId > 0) + { + _path = _iisClient.GetWebSite(siteId.Value).Path; + } + else + { + throw new Exception("No path specified"); + } + } + else + { + _path = _options.Path; + } + } + } +} diff --git a/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemArguments.cs b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemArguments.cs new file mode 100644 index 0000000..b99f400 --- /dev/null +++ b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemArguments.cs @@ -0,0 +1,7 @@ +namespace PKISharp.WACS.Plugins.ValidationPlugins.Http +{ + class FileSystemArguments : HttpValidationArguments + { + public long? ValidationSiteId { get; set; } + } +} diff --git a/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemArgumentsProvider.cs b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemArgumentsProvider.cs new file mode 100644 index 0000000..4d696e1 --- /dev/null +++ b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemArgumentsProvider.cs @@ -0,0 +1,24 @@ +using Fclp; +using PKISharp.WACS.Configuration; + +namespace PKISharp.WACS.Plugins.ValidationPlugins.Http +{ + class FileSystemArgumentsProvider : BaseArgumentsProvider<FileSystemArguments> + { + public override string Name => "FileSystem plugin"; + public override string Condition => "--validation filesystem"; + public override string Group => "Validation"; + + public override void Configure(FluentCommandLineParser<FileSystemArguments> parser) + { + parser.Setup(o => o.ValidationSiteId) + .As("validationsiteid") + .WithDescription("Specify IIS site to use for handling validation requests. This will be used to choose the web root path."); + } + + public override bool Active(FileSystemArguments current) + { + return current.ValidationSiteId != null; + } + } +} diff --git a/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptions.cs b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptions.cs new file mode 100644 index 0000000..4b70e2d --- /dev/null +++ b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptions.cs @@ -0,0 +1,35 @@ +using PKISharp.WACS.Plugins.Base; +using PKISharp.WACS.Services; + +namespace PKISharp.WACS.Plugins.ValidationPlugins.Http +{ + [Plugin("1c77b3a4-5310-4c46-92c6-00d866e84d6b")] + internal class FileSystemOptions : HttpValidationOptions<FileSystem> + { + public override string Name { get => "FileSystem"; } + public override string Description { get => "Save verification files on (network) path"; } + + public FileSystemOptions() : base() { } + public FileSystemOptions(HttpValidationOptions<FileSystem> source) : base(source) { } + + /// <summary> + /// Alternative site for validation. The path will be + /// determined from this site on each validation attempt + /// </summary> + public long? SiteId { get; set; } + + /// <summary> + /// Show to use what has been configured + /// </summary> + /// <param name="input"></param> + public override void Show(IInputService input) + { + base.Show(input); + if (SiteId != null) + { + input.Show("Site", SiteId.ToString()); + } + } + + } +} diff --git a/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs new file mode 100644 index 0000000..ea639d5 --- /dev/null +++ b/src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystemOptionsFactory.cs @@ -0,0 +1,69 @@ +using Microsoft.Web.Administration; +using PKISharp.WACS.Clients.IIS; +using PKISharp.WACS.DomainObjects; +using PKISharp.WACS.Extensions; +using PKISharp.WACS.Services; + +namespace PKISharp.WACS.Plugins.ValidationPlugins.Http +{ + /// <summary> + /// Classic FileSystem validation + /// </summary> + internal class FileSystemOptionsFactory : HttpValidationOptionsFactory<FileSystem, FileSystemOptions> + { + private readonly IIISClient _iisClient; + private readonly ILogService _log; + + public FileSystemOptionsFactory( + IIISClient iisClient, ILogService log, + IArgumentsService arguments) : base(arguments) + { + _log = log; + _iisClient = iisClient; + } + + public override bool PathIsValid(string path) => path.ValidPath(_log); + public override bool AllowEmtpy(Target target) => target.IIS; + + public override FileSystemOptions Default(Target target) + { + var args = _arguments.GetArguments<FileSystemArguments>(); + var ret = new FileSystemOptions(BaseDefault(target)); + if (target.IIS && _iisClient.HasWebSites) + { + + if (args.ValidationSiteId != null) + { + // Throws exception when not found + var site = _iisClient.GetWebSite(args.ValidationSiteId.Value); + ret.Path = site.Path; + ret.SiteId = args.ValidationSiteId.Value; + } + } + return ret; + } + + public override FileSystemOptions Aquire(Target target, IInputService inputService, RunLevel runLevel) + { + // Choose alternative site for validation + var ret = new FileSystemOptions(BaseAquire(target, inputService, runLevel)); + if (target.IIS && _iisClient.HasWebSites && string.IsNullOrEmpty(ret.Path)) + { + 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, + x => Choice.Create(x, x.Name, x.Id.ToString()), + "Automatic (target site)"); + if (site != null) + { + ret.Path = site.Path; + ret.SiteId = site.Id; + } + } + } + return ret; + } + } + +} |