public UnattendedResolver(ILogService log, ISettingsService settings, MainArguments arguments, IPluginService pluginService) { _log = log; _plugins = pluginService; _arguments = arguments; _settings = settings; }
public override bool Validate(IISWebArguments current, MainArguments main) { if (!base.Validate(current, main)) { return(false); } if (!string.IsNullOrEmpty(current.SSLPort)) { if (int.TryParse(current.SSLPort, out var port)) { if (port < 1 || port > 65535) { Log?.Error("Invalid --{param}, value should be between 1 and 65535", SslPortParameterName); return(false); } } else { Log?.Error("Invalid --{param}, value should be a number", SslPortParameterName); return(false); } } if (!string.IsNullOrEmpty(current.SSLIPAddress)) { if (!IPAddress.TryParse(current.SSLIPAddress, out _)) { Log?.Error("Invalid --{sslipaddress}", SslIpParameterName); return(false); } } return(true); }
public Wacs(ILifetimeScope container) { // Basic services _container = container; _scopeBuilder = container.Resolve <AutofacBuilder>(); _passwordGenerator = container.Resolve <PasswordGenerator>(); _log = _container.Resolve <ILogService>(); ShowBanner(); _arguments = _container.Resolve <IArgumentsService>(); _args = _arguments.MainArguments; if (_args != null) { if (_args.Verbose) { _log.SetVerbose(); _arguments.ShowCommandLine(); } _email = container.Resolve <EmailClient>(); _input = _container.Resolve <IInputService>(); _renewalService = _container.Resolve <IRenewalService>(); } else { Environment.Exit(1); } }
public BaseLegacyRenewalService( ISettingsService settings, MainArguments main, ILogService log) { _log = log; _configPath = settings.ConfigPath; }
public void Parse() { MainArguments parsedArgs = new MainArguments(); string[] args = new string[] { "Hello.exe" }; CommandLineUtility.ParseCommandLineArguments(args, parsedArgs); }
public ArgumentsService(ILogService log, ArgumentsParser parser) { _log = log; _parser = parser; if (parser.Validate()) { MainArguments = parser.GetArguments <MainArguments>(); } }
private void CreateConfigPath(MainArguments options, string?userRoot) { var configRoot = ""; if (!string.IsNullOrEmpty(userRoot)) { configRoot = userRoot; // Path configured in settings always wins, but // check for possible sub directories with client name // to keep bug-compatible with older releases that // created a subfolder inside of the users chosen config path foreach (var clientName in ClientNames) { var configRootWithClient = Path.Combine(userRoot, clientName); if (Directory.Exists(configRootWithClient)) { configRoot = configRootWithClient; Client.ClientName = clientName; break; } } } else { // When using a system folder, we have to create a sub folder // with the most preferred client name, but we should check first // if there is an older folder with an less preferred (older) // client name. var roots = new List <string> { Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) }; foreach (var root in roots) { // Stop looking if the directory has been found if (!Directory.Exists(configRoot)) { foreach (var clientName in ClientNames.ToArray().Reverse()) { Client.ClientName = clientName; configRoot = Path.Combine(root, clientName); if (Directory.Exists(configRoot)) { // Stop looking if the directory has been found break; } } } } } Client.ConfigurationPath = Path.Combine(configRoot, CleanFileName(options.BaseUri)); _log.Debug("Legacy config folder: {_configPath}", Client.ConfigurationPath); }
/// <summary> /// Reset the options for a(nother) run through the main menu /// </summary> /// <param name="options"></param> public static void Clear(this MainArguments options) { options.Target = null; options.Renew = false; options.FriendlyName = null; options.Force = false; options.List = false; options.Version = false; options.Help = false; }
public LegacySettingsService(ILogService log, MainArguments main, ISettingsService settings) { _log = log; UI = settings.UI; Acme = settings.Acme; ScheduledTask = settings.ScheduledTask; Notification = settings.Notification; Security = settings.Security; Script = settings.Script; // Copy so that the "ConfigurationPath" setting is not modified // from outside anymore Client = new ClientSettings() { ClientName = settings.Client.ClientName, ConfigurationPath = settings.Client.ConfigurationPath, LogPath = settings.Client.LogPath }; Validation = settings.Validation; Store = settings.Store; ExePath = settings.ExePath; ClientNames = new List <string>() { settings.Client.ClientName, "win-acme", "letsencrypt-win-simple" }; // Read legacy configuration file var installDir = new FileInfo(ExePath).DirectoryName; var legacyConfig = new FileInfo(Path.Combine(installDir, "settings.config")); var userRoot = default(string); if (legacyConfig.Exists) { var configXml = new XmlDocument(); configXml.LoadXml(File.ReadAllText(legacyConfig.FullName)); // Get custom configuration path: var configPath = configXml.SelectSingleNode("//setting[@name='ConfigurationPath']/value")?.InnerText ?? ""; if (!string.IsNullOrEmpty(configPath)) { userRoot = configPath; } // Get custom client name: var customName = configXml.SelectSingleNode("//setting[@name='ClientName']/value")?.InnerText ?? ""; if (!string.IsNullOrEmpty(customName)) { ClientNames.Insert(0, customName); } } BaseUri = new Uri(main.BaseUri); CreateConfigPath(main, userRoot); }
/// <summary> /// Find and/or create path of the configuration files /// </summary> /// <param name="options"></param> private void CreateConfigPath(MainArguments options) { var configRoot = ""; var userRoot = Settings.Default.ConfigurationPath; if (!string.IsNullOrEmpty(userRoot)) { configRoot = userRoot; // Path configured in settings always wins, but // check for possible sub directories with client name // to keep bug-compatible with older releases that // created a subfolder inside of the users chosen config path foreach (var clientName in ClientNames) { var configRootWithClient = Path.Combine(userRoot, clientName); if (Directory.Exists(configRootWithClient)) { configRoot = configRootWithClient; break; } } } else { // When using a system folder, we have to create a sub folder // with the most preferred client name, but we should check first // if there is an older folder with an less preferred (older) // client name. // Stop looking if the directory has been found if (!Directory.Exists(configRoot)) { var appData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); foreach (var clientName in ClientNames.Reverse()) { configRoot = Path.Combine(appData, clientName); if (Directory.Exists(configRoot)) { // Stop looking if the directory has been found break; } } } } // This only happens when invalid options are provided if (options != null) { ConfigPath = Path.Combine(configRoot, options.GetBaseUri().CleanBaseUri()); _log.Debug("Config folder: {_configPath}", ConfigPath); Directory.CreateDirectory(ConfigPath); } }
public TaskSchedulerService( ISettingsService settings, MainArguments arguments, IInputService input, ILogService log) { _arguments = arguments; _settings = settings; _input = input; _log = log; }
public TaskSchedulerService( ISettingsService settings, IArgumentsService options, IInputService input, ILogService log) { _options = options.MainArguments; _settings = settings; _input = input; _log = log; }
private IISOptions?Options(string commandLine) { var optionsParser = new ArgumentsParser(log, plugins, commandLine.Split(' ')); var input = new mock.InputService(new()); var secretService = new SecretServiceManager(new mock.SecretService(), input, log); var argsInput = new ArgumentsInputService(log, optionsParser, input, secretService); var args = new MainArguments(); var x = new IISOptionsFactory(log, helper, args, argsInput, userRoleService); return(x.Default().Result); }
public RenewalExecutor( MainArguments args, IAutofacBuilder scopeBuilder, ILogService log, IInputService input, ExceptionHandler exceptionHandler, IContainer container) { _args = args; _scopeBuilder = scopeBuilder; _log = log; _input = input; _exceptionHandler = exceptionHandler; _container = container; }
public void ParseReportTypeWithLongName() { MainArguments parsedArgs = new MainArguments(); string argument = "/report-type:Xml"; string[] args = new string[] { "Hello.exe", "mydll.dll", argument }; CommandLineUtility.ParseCommandLineArguments(args, parsedArgs); Assert.IsNotNull(parsedArgs.ReportTypes); Assert.AreEqual(1, parsedArgs.ReportTypes.Length); Assert.AreEqual(ReportType.Xml, parsedArgs.ReportTypes[0]); }
public CertificateService(IOptionsService options, ILogService log, AcmeClient client, ProxyService proxy, ISettingsService settingsService) { _log = log; _options = options.MainArguments; _client = client; _configPath = settingsService.ConfigPath; _proxy = proxy; InitCertificatePath(); }
public IISOptionsFactory( ILogService log, IISHelper iisHelper, MainArguments args, ArgumentsInputService arguments, IUserRoleService userRoleService) { _iisHelper = iisHelper; _log = log; _arguments = arguments; _args = args; Disabled = IIS.Disabled(userRoleService); }
public TaskSchedulerService( ISettingsService settings, IOptionsService options, IInputService input, ILogService log, RunLevel runLevel) { _options = options.MainArguments; _settings = settings; _input = input; _log = log; _runLevel = runLevel; }
public TaskSchedulerService( ISettingsService settings, IArgumentsService arguments, IInputService input, ILogService log, VersionService version) { _arguments = arguments.MainArguments; _settings = settings; _input = input; _log = log; _version = version; }
public Wacs( IContainer container, IAutofacBuilder scopeBuilder, ExceptionHandler exceptionHandler, ILogService logService, ISettingsService settingsService, IUserRoleService userRoleService, IDueDateService dueDateService, TaskSchedulerService taskSchedulerService, SecretServiceManager secretServiceManager) { // Basic services _container = container; _scopeBuilder = scopeBuilder; _exceptionHandler = exceptionHandler; _log = logService; _settings = settingsService; _userRoleService = userRoleService; _taskScheduler = taskSchedulerService; _secretServiceManager = secretServiceManager; _dueDateService = dueDateService; if (!string.IsNullOrWhiteSpace(_settings.UI.TextEncoding)) { try { Console.OutputEncoding = System.Text.Encoding.GetEncoding(_settings.UI.TextEncoding); } catch { _log.Warning("Error setting text encoding to {name}", _settings.UI.TextEncoding); } } _arguments = _container.Resolve <ArgumentsParser>(); _arguments.ShowCommandLine(); _args = _arguments.GetArguments <MainArguments>() !; _input = _container.Resolve <IInputService>(); _renewalStore = _container.Resolve <IRenewalStore>(); var renewalExecutor = container.Resolve <RenewalExecutor>( new TypedParameter(typeof(IContainer), _container)); _renewalCreator = container.Resolve <RenewalCreator>( new TypedParameter(typeof(IContainer), _container), new TypedParameter(typeof(RenewalExecutor), renewalExecutor)); _renewalManager = container.Resolve <RenewalManager>( new TypedParameter(typeof(IContainer), _container), new TypedParameter(typeof(RenewalExecutor), renewalExecutor), new TypedParameter(typeof(RenewalCreator), _renewalCreator)); }
public InteractiveResolver( ILogService log, IInputService inputService, ISettingsService settings, MainArguments arguments, IPluginService pluginService, RunLevel runLevel) : base(log, settings, arguments, pluginService) { _log = log; _input = inputService; _plugins = pluginService; _runLevel = runLevel; }
public RenewalExecutor( MainArguments args, IAutofacBuilder scopeBuilder, ILogService log, IInputService input, RenewalValidator validator, ExceptionHandler exceptionHandler, ILifetimeScope container) { _validator = validator; _args = args; _scopeBuilder = scopeBuilder; _log = log; _input = input; _exceptionHandler = exceptionHandler; _container = container; }
public SettingsService(ILogService log, MainArguments arguments, AccountArguments accArgs) { _log = log; _arguments = arguments; _accArgs = accArgs; var settingsFileName = "settings.json"; var settingsFileTemplateName = "settings_default.json"; _log.Verbose("Looking for {settingsFileName} in {path}", settingsFileName, VersionService.SettingsPath); var settings = new FileInfo(Path.Combine(VersionService.SettingsPath, settingsFileName)); var settingsTemplate = new FileInfo(Path.Combine(VersionService.ResourcePath, settingsFileTemplateName)); var useFile = settings; if (!settings.Exists) { if (!settingsTemplate.Exists) { // For .NET tool case settingsTemplate = new FileInfo(Path.Combine(VersionService.ResourcePath, settingsFileName)); } if (!settingsTemplate.Exists) { _log.Warning("Unable to locate {settings}", settingsFileName); } else { _log.Verbose("Copying {settingsFileTemplateName} to {settingsFileName}", settingsFileTemplateName, settingsFileName); try { if (!settings.Directory !.Exists) { settings.Directory.Create(); } settingsTemplate.CopyTo(settings.FullName); } catch (Exception ex) { _log.Error(ex, "Unable to create {settingsFileName}, falling back to defaults", settingsFileName); useFile = settingsTemplate; } } } try { new ConfigurationBuilder() .AddJsonFile(useFile.FullName, true, true) .Build() .Bind(this);
/// <summary> /// Get BaseUri to use /// </summary> /// <param name="options"></param> public static string GetBaseUri(this MainArguments options, bool import = false) { if (import) { return(options.ImportBaseUri ?? Properties.Settings.Default.DefaultBaseUriImport); } else if (options.Test) { return(options.BaseUri ?? Properties.Settings.Default.DefaultBaseUriTest); } else { return(options.BaseUri ?? Properties.Settings.Default.DefaultBaseUri); } }
public RegistryLegacyRenewalService( ILogService log, MainArguments main, ISettingsService settings, string hive) : base(settings, main, log) { _baseUri = main.BaseUri; _clientName = settings.ClientNames.Last(); _hive = $"HKEY_CURRENT_USER{Key}"; if (RenewalsRaw == null) { _hive = $"HKEY_LOCAL_MACHINE{Key}"; } _log.Debug("Read legacy renewals from registry {_registryHome}", _hive); }
public void ParseTwoReportTypeWithShortName() { MainArguments parsedArgs = new MainArguments(); string argument = "/rt:Xml"; string argument2 = "/rt:Html"; string[] args = new string[] { "Hello.exe", "mydll.dll", argument, argument2 }; CommandLineUtility.ParseCommandLineArguments(args, parsedArgs); Assert.IsNotNull(parsedArgs.ReportTypes); Assert.AreEqual(2, parsedArgs.ReportTypes.Length); Assert.AreEqual(ReportType.Xml, parsedArgs.ReportTypes[0]); Assert.AreEqual(ReportType.Html, parsedArgs.ReportTypes[1]); }
public Wacs(ILifetimeScope container) { // Basic services _container = container; _scopeBuilder = container.Resolve <AutofacBuilder>(); _passwordGenerator = container.Resolve <PasswordGenerator>(); _log = _container.Resolve <ILogService>(); ShowBanner(); _optionsService = _container.Resolve <IOptionsService>(); _input = _container.Resolve <IInputService>(); _arguments = _optionsService.MainArguments; if (_arguments != null) { _renewalService = _container.Resolve <IRenewalService>(); } }
public LegacySettingsService(ILogService log, MainArguments main, ISettingsService settings) { _log = log; _settings = settings; _clientNames = new List <string>() { "win-acme", "letsencrypt-win-simple" }; var customName = Properties.Settings.Default.ClientName; if (!string.IsNullOrEmpty(customName)) { _clientNames.Insert(0, customName); } CreateConfigPath(main); }
private void parseValue(string argument, string expectedOutput, string fieldName) { FieldInfo fi = typeof(MainArguments).GetField(fieldName); Assert.IsNotNull(fi); MainArguments parsedArgs = new MainArguments(); string[] args = new string[] { "Hello.exe", "mydll.dll", argument }; CommandLineUtility.ParseCommandLineArguments(args, parsedArgs); Console.WriteLine(parsedArgs.ToString()); Assert.AreEqual(expectedOutput, fi.GetValue(parsedArgs)); Assert.IsNotNull(parsedArgs.GetFilter()); }
public RenewalManager( IArgumentsService arguments, MainArguments args, IRenewalStore renewalStore, IContainer container, IInputService input, ILogService log, IAutofacBuilder autofacBuilder, ExceptionHandler exceptionHandler, RenewalExecutor renewalExecutor) { _renewalStore = renewalStore; _args = args; _input = input; _log = log; _arguments = arguments; _container = container; _scopeBuilder = autofacBuilder; _exceptionHandler = exceptionHandler; _renewalExecutor = renewalExecutor; }