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/FileSystem.cs | |
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/FileSystem.cs')
-rw-r--r-- | src/main.lib/Plugins/ValidationPlugins/Http/FileSystem/FileSystem.cs | 87 |
1 files changed, 87 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; + } + } + } +} |