Esempio n. 1
0
        public override IISSitesOptions Aquire(IArgumentsService arguments, IInputService inputService, RunLevel runLevel)
        {
            var ret   = new IISSitesOptions();
            var sites = _helper.GetSites(arguments.MainArguments.HideHttps, true).Where(x => x.Hidden == false).ToList();

            inputService.WritePagedList(sites.Select(x => Choice.Create(x, $"{x.Name} ({x.Hosts.Count()} bindings)", x.Id.ToString())).ToList());
            var sanInput = inputService.RequestString("Enter a comma separated list of SiteIds or 'S' for all sites").ToLower().Trim();

            sites = ProcessSiteIds(ret, sites, sanInput);
            if (sites == null)
            {
                return(null);
            }
            var hosts = sites.SelectMany(x => x.Hosts).Distinct().OrderBy(x => x);

            inputService.WritePagedList(hosts.Select(x => Choice.Create(x, "")));
            ret.ExcludeBindings = inputService.RequestString("Press enter to include all listed hosts, or type a comma-separated lists of exclusions").ParseCsv();

            if (runLevel.HasFlag(RunLevel.Advanced))
            {
                ret.CommonName = inputService.ChooseFromList(
                    "Select common name",
                    hosts.Except(ret.ExcludeBindings ?? new List <string>()),
                    (x) => new Choice <string>(x),
                    true);
            }
            return(ret);
        }
Esempio n. 2
0
        public override ScriptOptions Default(Target target, IArgumentsService arguments)
        {
            var args = arguments.GetArguments <ScriptArguments>();
            var ret  = new ScriptOptions();

            ProcessScripts(ret, args.DnsScript, args.DnsCreateScript, args.DnsDeleteScript);
            if (!string.IsNullOrEmpty(ret.Script))
            {
                if (!ret.Script.ValidFile(_log))
                {
                    _log.Error($"Invalid argument --{nameof(args.DnsScript).ToLower()}");
                    return(null);
                }
            }
            else
            {
                if (!ret.CreateScript.ValidFile(_log))
                {
                    _log.Error($"Invalid argument --{nameof(args.DnsCreateScript).ToLower()}");
                    return(null);
                }
                if (!string.IsNullOrEmpty(ret.DeleteScript))
                {
                    if (!ret.DeleteScript.ValidFile(_log))
                    {
                        _log.Error($"Invalid argument --{nameof(args.DnsDeleteScript).ToLower()}");
                        return(null);
                    }
                }
            }

            ProcessArgs(ret, args.DnsCreateScriptArguments, args.DnsDeleteScriptArguments);
            return(ret);
        }
Esempio n. 3
0
        public override IISBindingOptions Aquire(IArgumentsService arguments, IInputService inputService, RunLevel runLevel)
        {
            var ret      = new IISBindingOptions();
            var bindings = _helper.GetBindings(arguments.MainArguments.HideHttps).Where(x => !x.Hidden);

            if (!bindings.Any())
            {
                _log.Error($"No sites with named bindings have been configured in IIS. Add one or choose '{ManualOptions.DescriptionText}'.");
                return(null);
            }
            var chosenTarget = inputService.ChooseFromList(
                "Choose binding",
                bindings,
                x => Choice.Create(x),
                "Abort");

            if (chosenTarget != null)
            {
                ret.SiteId = chosenTarget.SiteId;
                ret.Host   = chosenTarget.HostUnicode;
                return(ret);
            }
            else
            {
                return(null);
            }
        }
        public override CentralSslOptions Default(IArgumentsService arguments)
        {
            var args = arguments.GetArguments <CentralSslArguments>();
            var path = Settings.Default.DefaultCentralSslStore;

            if (string.IsNullOrWhiteSpace(path))
            {
                path = arguments.TryGetRequiredArgument(nameof(args.CentralSslStore), args.CentralSslStore);
            }

            var password = Settings.Default.DefaultCentralSslPfxPassword;

            if (string.IsNullOrWhiteSpace(args.PfxPassword))
            {
                password = args.PfxPassword;
            }

            if (path.ValidPath(_log))
            {
                return(Create(path, password, args.KeepExisting));
            }
            else
            {
                throw new Exception("Invalid path specified");
            }
        }
Esempio n. 5
0
        private static void Arguments(IWampRealmServiceProvider serviceProvider)
        {
            IArgumentsService proxy = serviceProvider.GetCalleeProxy <IArgumentsService>();

            proxy.Ping();
            Console.WriteLine("Pinged!");

            int result = proxy.Add2(2, 3);

            Console.WriteLine("Add2: {0}", result);

            var starred = proxy.Stars();

            Console.WriteLine("Starred 1: {0}", starred);

            starred = proxy.Stars(nick: "Homer");
            Console.WriteLine("Starred 2: {0}", starred);

            starred = proxy.Stars(stars: 5);
            Console.WriteLine("Starred 3: {0}", starred);

            starred = proxy.Stars(nick: "Homer", stars: 5);
            Console.WriteLine("Starred 4: {0}", starred);

            string[] orders = proxy.Orders("coffee");
            Console.WriteLine("Orders 1: {0}", string.Join(", ", orders));

            orders = proxy.Orders("coffee", limit: 10);
            Console.WriteLine("Orders 2: {0}", string.Join(", ", orders));
        }
Esempio n. 6
0
        public SettingsService(ILogService log, IArgumentsService arguments)
        {
            _log       = log;
            _arguments = arguments;

            var installDir = new FileInfo(ExePath).DirectoryName;

            _log.Verbose($"Looking for settings.json in {installDir}");
            var settings         = new FileInfo(Path.Combine(installDir, "settings.json"));
            var settingsTemplate = new FileInfo(Path.Combine(installDir, "settings_default.json"));

            if (!settings.Exists && settingsTemplate.Exists)
            {
                _log.Verbose($"Copying settings_default.json to settings.json");
                settingsTemplate.CopyTo(settings.FullName);
            }

            try
            {
                new ConfigurationBuilder()
                .AddJsonFile(Path.Combine(installDir, "settings.json"), true, true)
                .Build()
                .Bind(this);
            }
            catch (Exception ex)
            {
                _log.Error(new Exception("Invalid settings.json", ex), "Unable to start program");
                return;
            }

            CreateConfigPath();
            CreateLogPath();
            CreateCachePath();
            Valid = true;
        }
 public FileSystemOptionsFactory(
     IIISClient iisClient, ILogService log,
     IArgumentsService arguments) : base(arguments)
 {
     _log       = log;
     _iisClient = iisClient;
 }
        public override ScriptOptions Default(Target target, IArgumentsService arguments)
        {
            var args = arguments.GetArguments <ScriptArguments>();
            var ret  = new ScriptOptions();

            ProcessScripts(ret, args.DnsScript, args.DnsCreateScript, args.DnsDeleteScript);
            if (!string.IsNullOrEmpty(ret.Script))
            {
                if (!ret.Script.ValidFile(_log))
                {
                    throw new ArgumentException(nameof(args.DnsCreateScript));
                }
            }
            else
            {
                if (!ret.CreateScript.ValidFile(_log))
                {
                    throw new ArgumentException(nameof(args.DnsCreateScript));
                }
                if (!string.IsNullOrEmpty(ret.DeleteScript))
                {
                    if (!ret.DeleteScript.ValidFile(_log))
                    {
                        throw new ArgumentException(nameof(args.DnsDeleteScript));
                    }
                }
            }

            ProcessArgs(ret, args.DnsCreateScriptArguments, args.DnsDeleteScriptArguments);
            return(ret);
        }
Esempio n. 9
0
        public NetworkCredentialOptions(IArgumentsService arguments, IInputService input)
        {
            var args = arguments.GetArguments <NetworkCredentialArguments>();

            UserName = arguments.TryGetArgument(args.UserName, input, "Username").Result;
            Password = new ProtectedString(arguments.TryGetArgument(args.Password, input, "Password", true).Result);
        }
Esempio n. 10
0
        public NetworkCredentialOptions(IArgumentsService arguments)
        {
            var args = arguments.GetArguments <NetworkCredentialArguments>();

            UserName = arguments.TryGetRequiredArgument(nameof(args.UserName), args.UserName);
            Password = new ProtectedString(arguments.TryGetRequiredArgument(nameof(args.Password), args.Password));
        }
Esempio n. 11
0
        public override IISSitesOptions Aquire(IArgumentsService arguments, IInputService input, RunLevel runLevel)
        {
            var ret   = new IISSitesOptions();
            var sites = _siteHelper.GetSites(arguments.MainArguments.HideHttps, true).
                        Where(x => x.Hidden == false).
                        Where(x => x.Hosts.Any()).
                        ToList();

            if (!sites.Any())
            {
                _log.Error($"No sites with named bindings have been configured in IIS. Add one or choose '{ManualOptions.DescriptionText}'.");
                return(null);
            }
            input.WritePagedList(sites.Select(x => Choice.Create(x, $"{x.Name} ({x.Hosts.Count()} bindings)", x.Id.ToString())).ToList());
            var sanInput = input.RequestString("Enter a comma separated list of SiteIds or 'S' for all sites");

            sites = ProcessSiteIds(ret, sites, sanInput);
            if (sites == null)
            {
                return(null);
            }
            var hosts = sites.SelectMany(x => x.Hosts).Distinct().OrderBy(x => x);

            if (_optionsHelper.AquireAdvancedOptions(input, hosts, runLevel, ret))
            {
                return(ret);
            }
            return(ret);
        }
Esempio n. 12
0
        public override IISSiteOptions Aquire(IArgumentsService arguments, IInputService input, RunLevel runLevel)
        {
            var ret   = new IISSiteOptions();
            var sites = _siteHelper.
                        GetSites(arguments.MainArguments.HideHttps, true).
                        Where(x => x.Hidden == false).
                        Where(x => x.Hosts.Any());

            if (!sites.Any())
            {
                _log.Error($"No sites with named bindings have been configured in IIS. Add one or choose '{ManualOptions.DescriptionText}'.");
                return(null);
            }
            var chosen = input.ChooseFromList("Choose site",
                                              sites,
                                              x => Choice.Create(x, x.Name),
                                              "Abort");

            if (chosen != null)
            {
                ret.SiteId = chosen.Id;
                if (_optionsHelper.AquireAdvancedOptions(input, chosen.Hosts, runLevel, ret))
                {
                    return(ret);
                }
            }
            return(null);
        }
Esempio n. 13
0
        public override IISSiteOptions Aquire(IArgumentsService arguments, IInputService inputService, RunLevel runLevel)
        {
            var ret    = new IISSiteOptions();
            var chosen = inputService.ChooseFromList("Choose site",
                                                     _helper.GetSites(arguments.MainArguments.HideHttps, true).Where(x => x.Hidden == false),
                                                     x => new Choice <IISSiteHelper.IISSiteOption>(x)
            {
                Description = x.Name
            },
                                                     true);

            if (chosen != null)
            {
                ret.SiteId = chosen.Id;
                ret.FriendlyNameSuggestion = $"Site-{chosen.Id}";

                // Exclude bindings
                inputService.WritePagedList(chosen.Hosts.Select(x => Choice.Create(x, "")));
                ret.ExcludeBindings = inputService.RequestString("Press enter to include all listed hosts, or type a comma-separated lists of exclusions").ParseCsv();
                if (runLevel.HasFlag(RunLevel.Advanced))
                {
                    ret.CommonName = inputService.ChooseFromList(
                        "Select common name",
                        chosen.Hosts.Except(ret.ExcludeBindings ?? new List <string>()),
                        x => new Choice <string>(x),
                        true);
                }
                return(ret);
            }
            return(null);
        }
Esempio n. 14
0
        public override IISWebOptions Aquire(Target target, IArgumentsService arguments, IInputService inputService, RunLevel runLevel)
        {
            var args = arguments.GetArguments <IISWebArguments>();
            var ret  = new IISWebOptions(args);
            var ask  = true;

            if (target.IIS)
            {
                if (runLevel.HasFlag(RunLevel.Advanced))
                {
                    ask = inputService.PromptYesNo("Use different site for installation?");
                }
                else
                {
                    ask = false;
                }
            }
            if (ask)
            {
                var chosen = inputService.ChooseFromList("Choose site to create new bindings",
                                                         _iisClient.WebSites,
                                                         x => new Choice <long>(x.Id)
                {
                    Description = x.Name,
                    Command     = x.Id.ToString()
                },
                                                         false);
                ret.SiteId = chosen;
            }
            return(ret);
        }
Esempio n. 15
0
        public override CsrOptions Aquire(IArgumentsService arguments, IInputService inputService, RunLevel runLevel)
        {
            var args = arguments.GetArguments <CsrArguments>();
            var ret  = new CsrOptions();

            do
            {
                ret.CsrFile = arguments.TryGetArgument(
                    args.CsrFile,
                    inputService,
                    "Enter the path to the CSR");
            }while (!ret.PkFile.ValidFile(_log));

            string pkFile;

            do
            {
                pkFile = arguments.TryGetArgument(args.CsrFile,
                                                  inputService,
                                                  "Enter the path to the corresponding private key, or <ENTER> to create a certificate without one");
            }while (!(string.IsNullOrWhiteSpace(pkFile) || pkFile.ValidFile(_log)));

            if (!string.IsNullOrWhiteSpace(pkFile))
            {
                ret.PkFile = pkFile;
            }

            return(ret);
        }
Esempio n. 16
0
 public override WebDavOptions Default(Target target, IArgumentsService arguments)
 {
     return(new WebDavOptions(BaseDefault(target, arguments))
     {
         Credential = new NetworkCredentialOptions(arguments)
     });
 }
Esempio n. 17
0
 public override WebDavOptions Aquire(Target target, IArgumentsService arguments, IInputService inputService, RunLevel runLevel)
 {
     return(new WebDavOptions(BaseAquire(target, arguments, inputService, runLevel))
     {
         Credential = new NetworkCredentialOptions(arguments, inputService)
     });
 }
Esempio n. 18
0
 public UnattendedResolver(ILogService log, ISettingsService settings, IArgumentsService arguments, IPluginService pluginService)
 {
     _log       = log;
     _plugins   = pluginService;
     _arguments = arguments;
     _settings  = settings;
 }
Esempio n. 19
0
        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 override IISSitesOptions Default(IArgumentsService arguments)
        {
            var ret        = new IISSitesOptions();
            var args       = arguments.GetArguments <IISSiteArguments>();
            var sites      = _helper.GetSites(false, false);
            var rawSiteIds = arguments.TryGetRequiredArgument(nameof(args.SiteId), args.SiteId);

            sites = ProcessSiteIds(ret, sites, rawSiteIds);
            if (sites == null)
            {
                return(null);
            }
            ret.ExcludeBindings = args.ExcludeBindings.ParseCsv();
            if (ret.ExcludeBindings != null)
            {
                ret.ExcludeBindings = ret.ExcludeBindings.Select(x => x.ConvertPunycode()).ToList();
            }
            var commonName = args.CommonName;

            if (!string.IsNullOrWhiteSpace(commonName))
            {
                commonName = commonName.ToLower().Trim().ConvertPunycode();
                if (sites.Any(s => s.Hosts.Contains(commonName)) &&
                    (ret.ExcludeBindings == null || !ret.ExcludeBindings.Contains(commonName)))
                {
                    ret.CommonName = commonName;
                }
                else
                {
                    _log.Error("Common name {commonName} not found or excluded", commonName);
                    return(null);
                }
            }
            return(ret);
        }
Esempio n. 21
0
        public override IISSiteOptions Default(IArgumentsService arguments)
        {
            var ret       = new IISSiteOptions();
            var args      = arguments.GetArguments <IISSiteArguments>();
            var rawSiteId = arguments.TryGetRequiredArgument(nameof(args.SiteId), args.SiteId);

            if (long.TryParse(rawSiteId, out long siteId))
            {
                var site = _siteHelper.GetSites(false, false).FirstOrDefault(binding => binding.Id == siteId);
                if (site != null)
                {
                    ret.SiteId = site.Id;
                    if (_optionsHelper.DefaultAdvancedOptions(args, site.Hosts, RunLevel.Unattended, ret))
                    {
                        return(ret);
                    }
                }
                else
                {
                    _log.Error("Unable to find SiteId {siteId}", siteId);
                }
            }
            else
            {
                _log.Error("Invalid SiteId {siteId}", args.SiteId);
            }
            return(null);
        }
Esempio n. 22
0
        public SettingsService(ILogService log, IArgumentsService arguments)
        {
            _log       = log;
            _arguments = arguments;

            var installDir = new FileInfo(ExePath).DirectoryName;

            _log.Verbose($"Looking for settings.json in {installDir}");
            var settings         = new FileInfo(Path.Combine(installDir, "settings.json"));
            var settingsTemplate = new FileInfo(Path.Combine(installDir, "settings_default.json"));

            if (!settings.Exists && settingsTemplate.Exists)
            {
                _log.Verbose($"Copying settings_default.json to settings.json");
                settingsTemplate.CopyTo(settings.FullName);
            }

            new ConfigurationBuilder()
            .AddJsonFile(Path.Combine(installDir, "settings.json"), true, true)
            .Build()
            .Bind(this);

            CreateConfigPath();
            CreateLogPath();
            CreateCachePath();
        }
Esempio n. 23
0
        public override IISBindingOptions Default(IArgumentsService arguments)
        {
            var ret       = new IISBindingOptions();
            var args      = arguments.GetArguments <IISBindingArguments>();
            var hostName  = arguments.TryGetRequiredArgument(nameof(args.Host), args.Host).ToLower();
            var rawSiteId = args.SiteId;
            var filterSet = _helper.GetBindings(false);

            if (!string.IsNullOrEmpty(rawSiteId))
            {
                if (long.TryParse(rawSiteId, out long siteId))
                {
                    filterSet = filterSet.Where(x => x.SiteId == siteId).ToList();
                }
                else
                {
                    _log.Error("Invalid SiteId {siteId}", rawSiteId);
                    return(null);
                }
            }
            var chosenTarget = filterSet.Where(x => x.HostUnicode == hostName || x.HostPunycode == hostName).FirstOrDefault();

            if (chosenTarget != null)
            {
                ret.SiteId = chosenTarget.SiteId;
                ret.Host   = chosenTarget.HostUnicode;
                return(ret);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 24
0
        public override AcmeOptions Aquire(Target target, IArgumentsService arguments, IInputService input, RunLevel runLevel)
        {
            var ret     = new AcmeOptions();
            Uri baseUri = null;

            while (baseUri == null)
            {
                try
                {
                    baseUri = new Uri(input.RequestString("URL of the acme-dns server"));
                }
                catch { }
            }
            ret.BaseUri = baseUri.ToString();
            var acmeDnsClient = new AcmeDnsClient(_dnsClient, _proxy, _log, _settings, input, ret.BaseUri);
            var identifiers   = target.Parts.SelectMany(x => x.Identifiers).Distinct();

            foreach (var identifier in identifiers)
            {
                if (!acmeDnsClient.EnsureRegistration(identifier.Replace("*.", ""), true))
                {
                    // Something failed or was aborted
                    return(null);
                }
            }
            return(ret);
        }
Esempio n. 25
0
        public override CentralSslOptions Aquire(IArgumentsService arguments, IInputService input, RunLevel runLevel)
        {
            var args = arguments.GetArguments <CentralSslArguments>();

            // Get path from command line, default setting or user input
            var path = args.CentralSslStore;

            if (string.IsNullOrWhiteSpace(path))
            {
                path = Settings.Default.DefaultCentralSslStore;
            }
            while (string.IsNullOrWhiteSpace(path) || !path.ValidPath(_log))
            {
                path = input.RequestString("Path to Central Certificate Store");
            }

            // Get password from command line, default setting or user input
            var password = args.PfxPassword;

            if (string.IsNullOrWhiteSpace(password))
            {
                password = Settings.Default.DefaultCentralSslPfxPassword;
            }
            if (string.IsNullOrEmpty(password))
            {
                password = input.ReadPassword("Password to use for the PFX files, or enter for none");
            }
            return(Create(path, password, args.KeepExisting));
        }
Esempio n. 26
0
        public SettingsService(ILogService log, IArgumentsService arguments)
        {
            _log = log;
            var settings         = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "settings.config");
            var settingsTemplate = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "settings_default.config");

            if (!settings.Exists && settingsTemplate.Exists)
            {
                settingsTemplate.CopyTo(settings.FullName);
            }

            _clientNames = new List <string>()
            {
                "win-acme"
            };
            var customName = Settings.Default.ClientName;

            if (!string.IsNullOrEmpty(customName))
            {
                _clientNames.Insert(0, customName);
            }

            CreateConfigPath(arguments.MainArguments);
            CreateCertificatePath();
            _log.Verbose("Settings {@settings}", this);
        }
Esempio n. 27
0
 public FtpOptionsFactory(
     ILogService log,
     IArgumentsService arguments,
     SecretServiceManager secretServiceManager) : base(arguments)
 {
     _log = log;
     _secretServiceManager = secretServiceManager;
 }
        public override DreamhostOptions Default(Target target, IArgumentsService arguments)
        {
            var az = arguments.GetArguments <DreamhostArguments>();

            return(new DreamhostOptions()
            {
                ApiKey = new ProtectedString(arguments.TryGetRequiredArgument(nameof(az.ApiKey), az.ApiKey)),
            });
        }
Esempio n. 29
0
        public override RsaOptions Default(IArgumentsService arguments)
        {
            var args = arguments.GetArguments <CsrArguments>();

            return(new RsaOptions()
            {
                OcspMustStaple = args.OcspMustStaple
            });
        }
        public override DreamhostOptions Aquire(Target target, IArgumentsService arguments, IInputService input, RunLevel runLevel)
        {
            var args = arguments.GetArguments <DreamhostArguments>();

            return(new DreamhostOptions()
            {
                ApiKey = new ProtectedString(arguments.TryGetArgument(args.ApiKey, input, "ApiKey", true)),
            });
        }