Exemple #1
0
        /// <summary>
        /// Ask the user to accept the terms of service dictated
        /// by the ACME service operator
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        private async Task <bool> AcceptTos(string filename, byte[] content)
        {
            var tosPath = Path.Combine(_settings.Client.ConfigurationPath, filename);

            _log.Verbose("Writing terms of service to {path}", tosPath);
            await File.WriteAllBytesAsync(tosPath, content);

            _input.CreateSpace();
            _input.Show($"Terms of service", tosPath);
            if (_arguments.GetArguments <AccountArguments>()?.AcceptTos ?? false)
            {
                return(true);
            }
            if (await _input.PromptYesNo($"Open in default application?", false))
            {
                try
                {
                    Process.Start(new ProcessStartInfo
                    {
                        FileName        = tosPath,
                        UseShellExecute = true
                    });
                }
                catch (Exception ex)
                {
                    _log.Error(ex, "Unable to start application");
                }
            }
            return(await _input.PromptYesNo($"Do you agree with the terms?", true));
        }
Exemple #2
0
        private string?TestScript(string parameters)
        {
            var argParser = new ArgumentsParser(log, new MockPluginService(log),
                                                $"--scriptparameters {parameters} --verbose".Split(' '));
            var args = argParser.GetArguments <ScriptArguments>();

            return(args?.ScriptParameters);
        }
Exemple #3
0
 public ArgumentsService(ILogService log, ArgumentsParser parser)
 {
     _log    = log;
     _parser = parser;
     if (parser.Validate())
     {
         MainArguments = parser.GetArguments <MainArguments>();
     }
 }
Exemple #4
0
        static void Main(string[] args)
        {
            Logger.Instance.Verbose = true;
            Dictionary <ArgumentKey, object> arguments;

            Logger.Instance.Info("Starting Routing Daemon...");

            try
            {
                // Load arguments
                arguments = ArgumentsParser.GetArguments(args);
            }
            catch
            {
                Logger.Instance.Error("Invalid arguments");
                return;
            }

            // Set the local node ID.
            DaemonBackEnd.Instance.LocalNode.NodeID = (int)arguments[ArgumentKey.NodeID];

            List <NodeConfiguration> config;

            try
            {
                // Load configuration file.
                config = ConfigFileParser.LoadConfigurationFromPath((string)arguments[ArgumentKey.ConfigFilePath]);
            }
            catch
            {
                return;
            }

            Logger.Instance.Debug("Loaded configuration file");

            // Configure all the neighbors of the local node
            DaemonBackEnd.Instance.ConfigureLocalNode(config);

            RoutingDaemon1 daemon = new RoutingDaemon1(
                DaemonBackEnd.Instance.LocalNode.Configuration.RoutingPort,
                DaemonBackEnd.Instance.LocalNode.Configuration.LocalPort
                );

            // Start the daemon
            daemon.Start();
            Logger.Instance.Info("Daemon Started Successfully");

            // Infinite Loop till the application exits.
            while (true)
            {
                System.Threading.Thread.Sleep(100000);
            }
        }
        public CitrixAdcClient(ILogService log, IEnvironment env, ISettingsService settings, ArgumentsParser arguments)
        {
            _log = log;
            var pemFilesPath = arguments.GetArguments <PemFilesArguments>()?.PemFilesPath;

            if (string.IsNullOrWhiteSpace(pemFilesPath))
            {
                pemFilesPath = settings.Store.PemFiles?.DefaultPath;
            }
            _pemFilesPath             = pemFilesPath ?? DefaultPemFilesPath;
            _pemFilesPassword         = settings.Store.PemFiles?.DefaultPassword ?? DefaultPemFilesPassword;
            _isDevelopmentEnvironment = env.IsDevelopment;
        }
Exemple #6
0
        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));
        }
Exemple #7
0
        public ILifetimeScope TestScope(List <string>?inputSequence = null, string commandLine = "")
        {
            var log             = new mock.LogService(false);
            var pluginService   = new real.PluginService(log);
            var argumentsParser = new ArgumentsParser(log, pluginService, commandLine.Split(' '));
            var input           = new mock.InputService(inputSequence ?? new List <string>());

            var builder = new ContainerBuilder();

            _ = builder.RegisterType <mock.SecretService>().As <real.ISecretService>().SingleInstance();
            _ = builder.RegisterType <real.SecretServiceManager>();
            _ = builder.RegisterInstance(log).As <real.ILogService>();
            _ = builder.RegisterInstance(argumentsParser).As <ArgumentsParser>();
            _ = builder.RegisterType <real.ArgumentsInputService>();
            _ = builder.RegisterInstance(pluginService).As <real.IPluginService>();
            _ = builder.RegisterInstance(input).As <real.IInputService>();
            _ = builder.RegisterInstance(argumentsParser.GetArguments <MainArguments>() !).SingleInstance();
            _ = builder.RegisterType <real.ValidationOptionsService>().As <real.IValidationOptionsService>().SingleInstance();
            _ = builder.RegisterType <mock.MockRenewalStore>().As <real.IRenewalStore>().SingleInstance();
            _ = builder.RegisterType <real.DueDateStaticService>().As <real.IDueDateService>().SingleInstance();
            _ = builder.RegisterType <mock.MockSettingsService>().As <real.ISettingsService>().SingleInstance();;
            _ = builder.RegisterType <mock.UserRoleService>().As <real.IUserRoleService>().SingleInstance();
            _ = builder.RegisterType <mock.ProxyService>().As <real.IProxyService>().SingleInstance();
            _ = builder.RegisterType <real.PasswordGenerator>().SingleInstance();
            _ = builder.RegisterType <RenewalCreator>().SingleInstance();
            _ = builder.RegisterType <real.SecretServiceManager>();

            pluginService.Configure(builder);

            _ = builder.RegisterType <real.DomainParseService>().SingleInstance();
            _ = builder.RegisterType <Mock.Clients.MockIISClient>().As <IIISClient>().SingleInstance();
            _ = builder.RegisterType <IISHelper>().SingleInstance();
            _ = builder.RegisterType <real.ExceptionHandler>().SingleInstance();
            _ = builder.RegisterType <UnattendedResolver>();
            _ = builder.RegisterType <InteractiveResolver>();
            _ = builder.RegisterType <real.AutofacBuilder>().As <real.IAutofacBuilder>().SingleInstance();
            _ = builder.RegisterType <AcmeClient>().SingleInstance();
            _ = builder.RegisterType <ZeroSsl>().SingleInstance();
            _ = builder.RegisterType <real.PemService>().SingleInstance();
            _ = builder.RegisterType <EmailClient>().SingleInstance();
            _ = builder.RegisterType <ScriptClient>().SingleInstance();
            _ = builder.RegisterType <LookupClientProvider>().SingleInstance();
            _ = builder.RegisterType <mock.CertificateService>().As <real.ICertificateService>().SingleInstance();
            _ = builder.RegisterType <real.TaskSchedulerService>().SingleInstance();
            _ = builder.RegisterType <real.NotificationService>().SingleInstance();
            _ = builder.RegisterType <RenewalValidator>().SingleInstance();
            _ = builder.RegisterType <RenewalExecutor>().SingleInstance();
            _ = builder.RegisterType <RenewalManager>().SingleInstance();

            return(builder.Build());
        }
Exemple #8
0
 public AcmeClient(
     IInputService inputService,
     ArgumentsParser arguments,
     ILogService log,
     ISettingsService settings,
     AccountManager accountManager,
     IProxyService proxy,
     ZeroSsl zeroSsl)
 {
     _log              = log;
     _settings         = settings;
     _arguments        = arguments;
     _accountArguments = _arguments.GetArguments <AccountArguments>() ?? new AccountArguments();
     _input            = inputService;
     _proxyService     = proxy;
     _accountManager   = accountManager;
     _zeroSsl          = zeroSsl;
 }
Exemple #9
0
 public T?GetArguments <T>() where T : class, new() => _parser.GetArguments <T>();
Exemple #10
0
        /// <summary>
        /// Configure dependency injection
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        internal static IContainer?GlobalScope(string[] args)
        {
            var builder = new ContainerBuilder();
            var logger  = new LogService();

            if (Verbose)
            {
                logger.SetVerbose();
            }
            // Not used but should be called anyway because it
            // checks if we're not running as dotnet.exe and also
            // prints some verbose messages that are interesting
            // to know very early in the start up process
            _ = new VersionService(logger);
            var pluginService   = new PluginService(logger);
            var argumentsParser = new ArgumentsParser(logger, pluginService, args);

            if (!argumentsParser.Validate())
            {
                return(null);
            }
            var mainArguments = argumentsParser.GetArguments <MainArguments>();

            if (mainArguments == null)
            {
                return(null);
            }
            var accountArguments = argumentsParser.GetArguments <AccountArguments>();
            var settingsService  = new SettingsService(logger, mainArguments, accountArguments);

            if (!settingsService.Valid)
            {
                return(null);
            }
            logger.SetDiskLoggingPath(settingsService.Client.LogPath !);

            _ = builder.RegisterInstance(argumentsParser);
            _ = builder.RegisterInstance(mainArguments);
            _ = builder.RegisterInstance(logger).As <ILogService>();
            _ = builder.RegisterInstance(settingsService).As <ISettingsService>();
            _ = builder.RegisterInstance(pluginService).As <IPluginService>();
            _ = builder.RegisterType <UserRoleService>().As <IUserRoleService>().SingleInstance();
            _ = builder.RegisterType <InputService>().As <IInputService>().SingleInstance();
            _ = builder.RegisterType <ProxyService>().As <IProxyService>().SingleInstance();
            _ = builder.RegisterType <UpdateClient>().SingleInstance();
            _ = builder.RegisterType <PasswordGenerator>().SingleInstance();
            _ = builder.RegisterType <RenewalStoreDisk>().As <IRenewalStore>().SingleInstance();

            pluginService.Configure(builder);

            _ = builder.RegisterType <DomainParseService>().SingleInstance();
            _ = builder.RegisterType <IISClient>().As <IIISClient>().InstancePerLifetimeScope();
            _ = builder.RegisterType <IISHelper>().SingleInstance();
            _ = builder.RegisterType <ExceptionHandler>().SingleInstance();
            _ = builder.RegisterType <UnattendedResolver>();
            _ = builder.RegisterType <InteractiveResolver>();
            _ = builder.RegisterType <AutofacBuilder>().As <IAutofacBuilder>().SingleInstance();
            _ = builder.RegisterType <AccountManager>().SingleInstance();
            _ = builder.RegisterType <AcmeClient>().SingleInstance();
            _ = builder.RegisterType <ZeroSsl>().SingleInstance();
            _ = builder.RegisterType <OrderManager>().SingleInstance();
            _ = builder.RegisterType <PemService>().SingleInstance();
            _ = builder.RegisterType <EmailClient>().SingleInstance();
            _ = builder.RegisterType <ScriptClient>().SingleInstance();
            _ = builder.RegisterType <LookupClientProvider>().SingleInstance();
            _ = builder.RegisterType <CertificateService>().As <ICertificateService>().SingleInstance();
            _ = builder.RegisterType <SecretServiceManager>().SingleInstance();
            _ = builder.RegisterType <JsonSecretService>().As <ISecretService>().SingleInstance();
            _ = builder.RegisterType <TaskSchedulerService>().SingleInstance();
            _ = builder.RegisterType <NotificationService>().SingleInstance();
            _ = builder.RegisterType <RenewalExecutor>().SingleInstance();
            _ = builder.RegisterType <RenewalValidator>().SingleInstance();
            _ = builder.RegisterType <RenewalManager>().SingleInstance();
            _ = builder.RegisterType <RenewalCreator>().SingleInstance();
            _ = builder.RegisterType <ArgumentsInputService>().SingleInstance();

            _ = builder.RegisterType <Wacs>();

            return(builder.Build());
        }
Exemple #11
0
 public T GetArguments <T>() where T : new()
 {
     return(_parser.GetArguments <T>());
 }
Exemple #12
0
 public T GetArguments <T>() where T : new() => _parser.GetArguments <T>();
Exemple #13
0
 public IISClient(ILogService log, ArgumentsParser arguments)
 {
     _log     = log;
     _iisHost = arguments.GetArguments <IISWebArguments>()?.IISHost ?? "";
     Version  = GetIISVersion(_iisHost);
 }