public override void Configure(IOfferRemoteComposition server)
        {
            var path = Path.GetFullPath(_path);
            var cert = string.IsNullOrWhiteSpace(_password) ? new X509Certificate2(path) : new X509Certificate2(path, _password);

            if (cert.HasPrivateKey)
            {
                string psUserArray = "@()";
                if (_certOptions != null && _certOptions.Values.PrivateKeyPermissions.Count > 0)
                {
                    var formattedUserArray = _certOptions.Values.PrivateKeyPermissions.Select(user => "'" + user + "'").ToList();
                    var users = string.Join(",", formattedUserArray);
                    psUserArray = string.Format("@({0})", users);
                }

                var destPath = string.Format(@"%temp%\{0}.pfx", Guid.NewGuid());
                server.Deploy.File(path, destPath);
                server.ExecuteRemote.PowerShell("$path='" + destPath + "'; $password='******'; $privateKeyUsers = " + psUserArray + "; [ConDep.Remote.CertificateInstaller]::InstallPfx($path, $password, $privateKeyUsers);", opt => opt.RequireRemoteLib().WaitIntervalInSeconds(30));
            }
            else
            {
                var base64Cert = Convert.ToBase64String(cert.RawData);
                server.ExecuteRemote.PowerShell(string.Format("[ConDep.Remote.CertificateInstaller]::InstallCertFromBase64('{0}');", base64Cert), opt => opt.RequireRemoteLib().WaitIntervalInSeconds(20));
            }
        }
Example #2
0
        private void InstallMsiFromUrl(IOfferRemoteComposition server, Uri url)
        {
            var dstPath = string.Format(@"$env:temp\{0}", Guid.NewGuid() + ".msi");

            server.OnlyIf(InstallCondtion)
            .Execute.PowerShell(string.Format("Install-ConDepMsiFromUri \"{0}\" \"{1}\"", url, dstPath), SetPowerShellOptions);
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var builder = new StringBuilder();
            CreateKeyCmd(builder, _root.ToString(), new WindowsRegistrySubKey(_key, _defaultValue, _values, _keys));

            server.Execute.PowerShell(builder.ToString());
        }
Example #4
0
        public override void Configure(IOfferRemoteComposition server, IOfferInfrastructure require)
        {
            var bindings = _options.Values.HttpBindings.Select(httpBinding => string.Format("@{{protocol='http';bindingInformation='{0}:{1}:{2}'}}", httpBinding.Ip, httpBinding.Port, httpBinding.HostName)).ToList();

            foreach (var httpsBinding in _options.Values.HttpsBindings)
            {
                if (httpsBinding.FindType == X509FindType.FindByThumbprint)
                {
                    httpsBinding.FindName = httpsBinding.FindName.Replace(" ", "");
                }
                var type = httpsBinding.FindType.GetType();
                bindings.Add(string.Format("@{{protocol='https';bindingInformation='{0}:{1}:{2}';findType=[{3}]::{4};findValue='{5}'}}", httpsBinding.BindingOptions.Ip, httpsBinding.BindingOptions.Port, httpsBinding.BindingOptions.HostName, type.FullName, httpsBinding.FindType, httpsBinding.FindName));
            }

            server.ExecuteRemote.PowerShell(string.Format(@"New-ConDepIisWebSite '{0}' {1} {2} {3} '{4}';"
                                                          , _webSiteName
                                                          , _id
                                                          , "@(" + string.Join(",", bindings) + ")"
                                                          , (string.IsNullOrWhiteSpace(_options.Values.PhysicalPath) ? "$null" : "'" + _options.Values.PhysicalPath + "'")
                                                          , _options.Values.AppPool)
                                            , o => o.WaitIntervalInSeconds(30).RetryAttempts(3));

            foreach (var webApp in _options.Values.WebApps)
            {
                require.IISWebApp(webApp.Item1, _webSiteName, webApp.Item2);
            }
        }
Example #5
0
        public override void Configure(IOfferRemoteComposition server, IOfferInfrastructure require)
        {
            var bindings = _options.Values.HttpBindings.Select(httpBinding => string.Format("@{{protocol='http';bindingInformation='{0}:{1}:{2}'}}", httpBinding.Ip, httpBinding.Port, httpBinding.HostName)).ToList();

            foreach (var httpsBinding in _options.Values.HttpsBindings)
            {
                if (httpsBinding.FindType == X509FindType.FindByThumbprint)
                {
                    httpsBinding.FindName = httpsBinding.FindName.Replace(" ", "");
                }
                var type = httpsBinding.FindType.GetType();
                bindings.Add(string.Format("@{{protocol='https';bindingInformation='{0}:{1}:{2}';findType=[{3}]::{4};findValue='{5}'}}", httpsBinding.BindingOptions.Ip, httpsBinding.BindingOptions.Port, httpsBinding.BindingOptions.HostName, type.FullName, httpsBinding.FindType, httpsBinding.FindName));
            }

            server.ExecuteRemote.PowerShell(string.Format(@"New-ConDepIisWebSite '{0}' {1} {2} {3} '{4}';"
                , _webSiteName
                , _id
                , "@(" + string.Join(",", bindings) + ")"
                , (string.IsNullOrWhiteSpace(_options.Values.PhysicalPath) ? "$null" : "'" + _options.Values.PhysicalPath + "'")
                , _options.Values.AppPool)
                , o => o.WaitIntervalInSeconds(30).RetryAttempts(3));

            foreach(var webApp in _options.Values.WebApps)
            {
                require.IISWebApp(webApp.Item1, _webSiteName, webApp.Item2);
            }
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            string uacEnabled = string.Format(@"
$regKey = Get-ItemProperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name ""EnableLUA""
return $regKey.EnableLUA -eq ${0}", !_enabled);

            const string restartNeeded = @"
$restartEnvVar = [Environment]::GetEnvironmentVariable(""CONDEP_RESTART_NEEDED"",""Machine"")
return $restartEnvVar -eq 'true'
";

            //Assume restart is not necessary.
            server.Configure.EnvironmentVariable("CONDEP_RESTART_NEEDED", "false", EnvironmentVariableTarget.Machine);

            //Set uac if not set. Set env variable for restarting server necessary.
            server
            .OnlyIf(uacEnabled)
            .Configure
            .WindowsRegistry(reg =>
                             reg.SetValue(
                                 WindowsRegistryRoot.HKEY_LOCAL_MACHINE,
                                 @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System",
                                 "EnableLUA",
                                 _enabled ? "1" : "0",
                                 RegistryValueKind.DWord
                                 )
                             )
            .EnvironmentVariable("CONDEP_RESTART_NEEDED", "true", EnvironmentVariableTarget.Machine);

            //Restart server and set env variable for restart NOT necessary, since the machine rebooted.
            server
            .OnlyIf(restartNeeded)
            .Restart()
            .Configure.EnvironmentVariable("CONDEP_RESTART_NEEDED", "false", EnvironmentVariableTarget.Machine);
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var setDnsScript = String.Format(@"
            $nics = Get-WmiObject Win32_NetworkAdapterConfiguration -ErrorAction Inquire | Where{{$_.IPEnabled -eq ""TRUE""}}
            $newDNS = {0}

            foreach($nic in $nics)
            {{
            Write-Host ""`tExisting DNS Servers "" $nic.DNSServerSearchOrder
            if(Compare-Object $nic.DNSServerSearchOrder $newDNS)
            {{
            Write-Host ""`tDNS servers differes from provided. Overwriting now...""
            $result = $nic.SetDNSServerSearchOrder($newDNS)

            if($result.ReturnValue -eq 0)
            {{
            Write-Host ""`tSuccessfully Changed DNS Servers""
            }}
            else
            {{
            throw ""Failed to Change DNS Servers""
            }}
            }}
            else {{
            Write-Host ""`tDNS servers is equal to provided. Doing nothing.""
            }}
            }}
            ", FormattedIpList());

            server.Execute.PowerShell(setDnsScript);
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            string uacEnabled = string.Format(@"
            $regKey = Get-ItemProperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name ""EnableLUA""
            return $regKey.EnableLUA -eq ${0}", !_enabled);

            const string restartNeeded = @"
            $restartEnvVar = [Environment]::GetEnvironmentVariable(""CONDEP_RESTART_NEEDED"",""Machine"")
            return $restartEnvVar -eq 'true'
            ";

            //Assume restart is not necessary.
            server.Configure.EnvironmentVariable("CONDEP_RESTART_NEEDED", "false", EnvironmentVariableTarget.Machine);

            //Set uac if not set. Set env variable for restarting server necessary.
            server
                .OnlyIf(uacEnabled)
                    .Configure
                    .WindowsRegistry(reg =>
                        reg.SetValue(
                            WindowsRegistryRoot.HKEY_LOCAL_MACHINE,
                            @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System",
                            "EnableLUA",
                            _enabled ? "1" : "0",
                            RegistryValueKind.DWord
                        )
                    )
                    .EnvironmentVariable("CONDEP_RESTART_NEEDED", "true", EnvironmentVariableTarget.Machine);

            //Restart server and set env variable for restart NOT necessary, since the machine rebooted.
            server
                .OnlyIf(restartNeeded)
                    .Restart()
                    .Configure.EnvironmentVariable("CONDEP_RESTART_NEEDED", "false", EnvironmentVariableTarget.Machine);
        }
 public override void Configure(IOfferRemoteComposition server)
 {
     foreach (var script in _scripts)
     {
         server.Deploy.File(script, @"%temp%\ConDepPowerShellScripts\ConDep\" + Path.GetFileName(script));
     }
 }
        public override void Configure(IOfferRemoteComposition server)
        {
            var removeFeatures = _featuresToRemove.Count > 0 ? string.Join(",", _featuresToRemove) : "$null";
            var addFeatures    = string.Join(",", _featuresToAdd);

            server.Execute.PowerShell(string.Format("Set-ConDepWindowsFeatures {0} {1}", addFeatures, removeFeatures));
        }
 public override void Configure(IOfferRemoteComposition server)
 {
     foreach (var script in _scripts)
     {
         server.Deploy.File(script, @"%temp%\ConDepPowerShellScripts\ConDep\" + Path.GetFileName(script));
     }
 }
        public override void Configure(IOfferRemoteComposition server)
        {
            var path = Path.GetFullPath(_path);
            var cert = string.IsNullOrWhiteSpace(_password) ? new X509Certificate2(path) : new X509Certificate2(path, _password);

            if(cert.HasPrivateKey)
            {
                string psUserArray = "@()";
                if(_certOptions != null && _certOptions.Values.PrivateKeyPermissions.Count > 0)
                {
                    var formattedUserArray = _certOptions.Values.PrivateKeyPermissions.Select(user => "'" + user + "'").ToList();
                    var users = string.Join(",", formattedUserArray);
                    psUserArray = string.Format("@({0})", users);
                }

                var destPath = string.Format(@"%temp%\{0}.pfx", Guid.NewGuid());
                server.Deploy.File(path, destPath);
                server.ExecuteRemote.PowerShell("$path='" + destPath + "'; $password='******'; $privateKeyUsers = " + psUserArray + "; [ConDep.Remote.CertificateInstaller]::InstallPfx($path, $password, $privateKeyUsers);", opt => opt.RequireRemoteLib().WaitIntervalInSeconds(30));
            }
            else
            {
                var base64Cert = Convert.ToBase64String(cert.RawData);
                server.ExecuteRemote.PowerShell(string.Format("[ConDep.Remote.CertificateInstaller]::InstallCertFromBase64('{0}');", base64Cert), opt => opt.RequireRemoteLib().WaitIntervalInSeconds(20));
            }
        }
Example #13
0
        public override void Configure(IOfferRemoteComposition server)
        {
            var installParams = string.Format("/install /serviceName:\"{0}\" /displayName:\"{0}\" {1}", _serviceName, _profile);

            server.Deploy.WindowsServiceWithInstaller(_serviceName, _serviceName, _sourcePath, _destPath, _serviceInstallerName,
                                                      installParams, _options);
        }
 protected void ConfigureRemoveService(IOfferRemoteComposition server)
 {
     var remove = string.Format("Remove-ConDepWinService '{0}' 0 {1}", _serviceName,
                                "$" + _values.IgnoreFailureOnServiceStartStop);
     server.ExecuteRemote.PowerShell(remove,
                                     o =>
                                     o.WaitIntervalInSeconds(60).ContinueOnError(_values.IgnoreFailureOnServiceStartStop));
 }
Example #15
0
 public override void Configure(IOfferRemoteComposition server)
 {
     server.Execute.PowerShell(string.Format(@"New-ConDepWebApp '{0}' '{1}' {2} {3};"
                                             , _webAppName
                                             , _webSiteName
                                             , (_options == null || string.IsNullOrWhiteSpace(_options.PhysicalPath)) ? "$null" : "'" + _options.PhysicalPath + "'"
                                             , (_options == null || string.IsNullOrWhiteSpace(_options.AppPool)) ? "$null" : "'" + _options.AppPool + "'"));
 }
 public override void Configure(IOfferRemoteComposition server)
 {
     server.Execute.PowerShell(string.Format(@"New-ConDepWebApp '{0}' '{1}' {2} {3};"
         , _webAppName
         , _webSiteName
         , (_options == null || string.IsNullOrWhiteSpace(_options.PhysicalPath)) ? "$null" : "'" + _options.PhysicalPath + "'"
         , (_options == null || string.IsNullOrWhiteSpace(_options.AppPool)) ? "$null" : "'" + _options.AppPool + "'"));
 }
Example #17
0
        public override void Configure(IOfferRemoteComposition server)
        {
            var builder = new StringBuilder();

            CreateKeyCmd(builder, _root.ToString(), new WindowsRegistrySubKey(_key, _defaultValue, _values, _keys));

            server.Execute.PowerShell(builder.ToString());
        }
 public override void Configure(IOfferRemoteComposition server)
 {
     ConfigureRemoveService(server);
     ConfigureDeployment(server);
     ConfigureInstallService(server);
     ConfigureServiceFailure(server);
     ConfigureServiceConfig(server);
     ConfigureServiceStart(server);
 }
Example #19
0
        protected void ConfigureUserRights(IOfferRemoteComposition server)
        {
            if (string.IsNullOrWhiteSpace(_values.UserName))
            {
                return;
            }

            server.Execute.PowerShell("$userName=\"" + _values.UserName + "\"; [ConDep.Dsl.Remote.Helpers.LsaWrapperCaller]::AddLogonAsAServiceRights($userName)", opt => opt.RequireRemoteLib());
        }
Example #20
0
 public override void Configure(IOfferRemoteComposition server, IOfferInfrastructure require)
 {
     server.ExecuteRemote.PowerShell(string.Format(@"New-ConDepWebApp '{0}' '{1}' {2} {3};"
         , _webAppName
         , _webSiteName
         , (_options == null || string.IsNullOrWhiteSpace(_options.PhysicalPath)) ? "$null" : "'" + _options.PhysicalPath + "'"
         , (_options == null || string.IsNullOrWhiteSpace(_options.AppPool)) ? "$null" : "'" + _options.AppPool + "'")
     , psOptions => psOptions.WaitIntervalInSeconds(30));
 }
        protected void ConfigureServiceFailure(IOfferRemoteComposition server)
        {
            var serviceFailureCommand = _values.GetServiceFailureCommand(_serviceName);

            if (!string.IsNullOrWhiteSpace(serviceFailureCommand))
            {
                server.ExecuteRemote.DosCommand(serviceFailureCommand);
            }
        }
        protected void ConfigureRemoveService(IOfferRemoteComposition server)
        {
            var remove = string.Format("Remove-ConDepWinService '{0}' 0 {1}", _serviceName,
                                       "$" + _values.IgnoreFailureOnServiceStartStop);

            server.ExecuteRemote.PowerShell(remove,
                                            o =>
                                            o.WaitIntervalInSeconds(60).ContinueOnError(_values.IgnoreFailureOnServiceStartStop));
        }
 public override void Configure(IOfferRemoteComposition server)
 {
     ConfigureRemoveService(server);
     ConfigureDeployment(server);
     ConfigureInstallService(server);
     ConfigureServiceFailure(server);
     ConfigureServiceConfig(server);
     ConfigureServiceStart(server);
 }
Example #24
0
 public override void Configure(IOfferRemoteComposition server, IOfferInfrastructure require)
 {
     server.ExecuteRemote.PowerShell(string.Format(@"New-ConDepWebApp '{0}' '{1}' {2} {3};"
                                                   , _webAppName
                                                   , _webSiteName
                                                   , (_options == null || string.IsNullOrWhiteSpace(_options.PhysicalPath)) ? "$null" : "'" + _options.PhysicalPath + "'"
                                                   , (_options == null || string.IsNullOrWhiteSpace(_options.AppPool)) ? "$null" : "'" + _options.AppPool + "'")
                                     , psOptions => psOptions.WaitIntervalInSeconds(30));
 }
Example #25
0
        private void InstallMsiFromFile(IOfferRemoteComposition server, string src)
        {
            var dstPath = Path.Combine(@"%temp%\", Path.GetFileName(src));

            server.OnlyIf(InstallCondtion)
            .Deploy.File(src, dstPath);

            server.OnlyIf(InstallCondtion)
            .Execute.PowerShell(string.Format("Install-ConDepMsiFromFile \"{0}\"", dstPath), SetPowerShellOptions);
        }
Example #26
0
        private void InstallExecutableFromUri(IOfferRemoteComposition server, Uri srcExecutableUri, string exeParams)
        {
            var filename  = Guid.NewGuid() + ".exe";
            var psDstPath = string.Format(@"$env:temp\{0}", filename);

            server.OnlyIf(InstallCondition)
            .Execute
            .PowerShell(string.Format("Get-ConDepRemoteFile \"{0}\" \"{1}\"", srcExecutableUri, psDstPath))
            .PowerShell(string.Format("cd $env:temp; cmd /c \"{0} {1}\"", filename, exeParams), SetPowerShellOptions);
        }
        private void InstallMsiFromFile(IOfferRemoteComposition server, string src)
        {
            var dstPath = Path.Combine(@"%temp%\", Path.GetFileName(src));

            server.OnlyIf(InstallCondtion)
                .Deploy.File(src, dstPath);

            server.OnlyIf(InstallCondtion)
                .Execute.PowerShell(string.Format("Install-ConDepMsiFromFile \"{0}\"", dstPath), SetPowerShellOptions);
        }
 protected void ConfigureServiceStart(IOfferRemoteComposition server)
 {
     if (!_values.DoNotStart)
     {
         var start = string.Format("Start-ConDepWinService '{0}' {1} {2}", _serviceName, _values.TimeOutInSeconds,
                                   "$" + _values.IgnoreFailureOnServiceStartStop);
         server.Execute.PowerShell(start,
                                         o => o.ContinueOnError(
                                             _values.IgnoreFailureOnServiceStartStop));
     }
 }
Example #29
0
        private void InstallExecutableFromFile(IOfferRemoteComposition server, string srcExecutableFilePath, string exeParams)
        {
            var filename = Path.GetFileName(srcExecutableFilePath);
            var dstPath  = Path.Combine(@"%temp%\", filename);

            server.OnlyIf(InstallCondition)
            .Deploy.File(srcExecutableFilePath, dstPath);

            server.OnlyIf(InstallCondition)
            .Execute.PowerShell(string.Format("cd $env:temp; cmd /c \"{0} {1}\"", filename, exeParams), SetPowerShellOptions);
        }
Example #30
0
 protected void ConfigureServiceStart(IOfferRemoteComposition server)
 {
     if (!_values.DoNotStart)
     {
         var start = string.Format("Start-ConDepWinService '{0}' {1} {2}", _serviceName, _values.TimeOutInSeconds,
                                   "$" + _values.IgnoreFailureOnServiceStartStop);
         server.Execute.PowerShell(start,
                                   o => o.ContinueOnError(
                                       _values.IgnoreFailureOnServiceStartStop));
     }
 }
        public override void Configure(IOfferRemoteComposition server)
        {
            var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

            try
            {
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                var certs = store.Certificates;

                var findResult = certs.Find(_findType, _findValue, false);
                if (findResult == null || findResult.Count == 0)
                {
                    throw new ConDepCertificateNotFoundException(string.Format("Certificate with find type [{0}] and term [{1}] not found.", _findType, _findValue));
                }

                if (findResult.Count > 1)
                {
                    throw new ConDepCertificateNotFoundException(string.Format("Certificate with find type [{0}] and term [{1}] returned {2} certificates. Please narrow your search to only return one certificate.", _findType, _findValue, findResult.Count));
                }

                var cert = findResult[0];

                if (cert.HasPrivateKey)
                {
                    var guid       = Guid.NewGuid();
                    var destPath   = string.Format(@"%windir%\temp\{0}.pfx", guid);
                    var sourcePath = Path.Combine(Path.GetTempPath(), guid + ".pfx");

                    const string password     = "******";
                    var          exportedCert = cert.Export(X509ContentType.Pkcs12, password);
                    File.WriteAllBytes(sourcePath, exportedCert);

                    server.Deploy.File(sourcePath, destPath);

                    var formattedUserArray = _certOptions.Values.PrivateKeyPermissions.Select(user => "'" + user + "'").ToList();
                    var users       = string.Join(",", formattedUserArray);
                    var psUserArray = string.Format("@({0})", users);

                    server.Execute.PowerShell("$path='" + destPath + "'; $password='******'; $privateKeyUsers = " + psUserArray + "; [ConDep.Dsl.Remote.Helpers.CertificateInstaller]::InstallPfx($path, $password, $privateKeyUsers);", opt => opt.RequireRemoteLib());
                }
                else
                {
                    var base64Cert = Convert.ToBase64String(cert.RawData);
                    server.Execute.PowerShell(string.Format("[ConDep.Dsl.Remote.Helpers.CertificateInstaller]::InstallCertFromBase64('{0}');", base64Cert), opt => opt.RequireRemoteLib());
                }
            }
            finally
            {
                store.Close();
            }
        }
 public override void Configure(IOfferRemoteComposition server)
 {
     switch (_sourceType)
     {
         case FileSourceType.File:
             InstallExecutableFromFile(server, _srcExecutableFilePath, _exeParams);
             break;
         case FileSourceType.Url:
             InstallExecutableFromUri(server, _srcExecutableUri, _exeParams);
             break;
         default:
             throw new ConDepInstallationFailureException("Invalid fine source type");
     }
 }
Example #33
0
        protected override void ConfigureInstallService(IOfferRemoteComposition server)
        {
            var installCmd = string.Format("New-ConDepWinService '{0}' '{1}' {2} {3} {4}",
                                           _serviceName,
                                           Path.Combine(_destDir, _relativeExePath) + " " + _values.ExeParams,
                                           string.IsNullOrWhiteSpace(_displayName) ? "$null" : ("'" + _displayName + "'"),
                                           string.IsNullOrWhiteSpace(_values.Description)
                                               ? "$null"
                                               : ("'" + _values.Description + "'"),
                                           _values.StartupType.HasValue ? "'" + _values.StartupType + "'" : "'" + ServiceStartMode.Manual + "'"
                                           );

            server.Execute.PowerShell(installCmd);
        }
 public override void Configure(IOfferRemoteComposition server)
 {
     server.Execute.PowerShell(string.Format(@"
     $continueOnError = {0}
     cmd /c {1}
     if($lastexitcode -gt 0) {{
     if($continueOnError) {{
     Write-Warning ""Exit code $lastexitcode""
     }}
     else {{
     throw ""Exit code $lastexitcode""
     }}
     }}", _values.ContinueOnError ? "$true": "$false", _cmd));
 }
 public override void Configure(IOfferRemoteComposition server)
 {
     switch (_srcType)
     {
         case FileSourceType.File:
             InstallMsiFromFile(server, _srcMsiFilePath);
             break;
         case FileSourceType.Url:
             InstallMsiFromUrl(server, _srcMsiUri);
             break;
         default:
             throw new Exception("Source type unknown");
     }
 }
Example #36
0
        protected override void ConfigureInstallService(IOfferRemoteComposition server)
        {
            var installCmd = string.Format("New-ConDepWinService '{0}' '{1}' {2} {3} {4}",
                                           _serviceName,
                                           Path.Combine(_destDir, _relativeExePath) + " " + _values.ExeParams,
                                           string.IsNullOrWhiteSpace(_displayName) ? "$null" : ("'" + _displayName + "'"),
                                           string.IsNullOrWhiteSpace(_values.Description)
                                               ? "$null"
                                               : ("'" + _values.Description + "'"),
                                           _values.StartupType.HasValue ? "'" + _values.StartupType + "'" : "$null"
                );

            server.ExecuteRemote.PowerShell(installCmd, opt => opt.WaitIntervalInSeconds(60));
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            try
            {
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                var certs = store.Certificates;

                var findResult = certs.Find(_findType, _findValue, false);
                if (findResult == null || findResult.Count == 0)
                {
                    throw new ConDepCertificateNotFoundException(string.Format("Certificate with find type [{0}] and term [{1}] not found.", _findType, _findValue));
                }

                if (findResult.Count > 1)
                {
                    throw new ConDepCertificateNotFoundException(string.Format("Certificate with find type [{0}] and term [{1}] returned {2} certificates. Please narrow your search to only return one certificate.", _findType, _findValue, findResult.Count));
                }

                var cert = findResult[0];

                if (cert.HasPrivateKey)
                {
                    var guid = Guid.NewGuid();
                    var destPath = string.Format(@"%windir%\temp\{0}.pfx", guid);
                    var sourcePath = Path.Combine(Path.GetTempPath(), guid + ".pfx");

                    const string password = "******";
                    var exportedCert = cert.Export(X509ContentType.Pkcs12, password);
                    File.WriteAllBytes(sourcePath, exportedCert);

                    server.Deploy.File(sourcePath, destPath);

                    var formattedUserArray = _certOptions.Values.PrivateKeyPermissions.Select(user => "'" + user + "'").ToList();
                    var users = string.Join(",", formattedUserArray);
                    var psUserArray = string.Format("@({0})", users);

                    server.Execute.PowerShell("$path='" + destPath + "'; $password='******'; $privateKeyUsers = " + psUserArray + "; [ConDep.Dsl.Remote.Helpers.CertificateInstaller]::InstallPfx($path, $password, $privateKeyUsers);", opt => opt.RequireRemoteLib());
                }
                else
                {
                    var base64Cert = Convert.ToBase64String(cert.RawData);
                    server.Execute.PowerShell(string.Format("[ConDep.Dsl.Remote.Helpers.CertificateInstaller]::InstallCertFromBase64('{0}');", base64Cert), opt => opt.RequireRemoteLib());
                }
            }
            finally
            {
                store.Close();
            }
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            server.Execute.PowerShell(string.Format(@"
$continueOnError = {0}
cmd /c {1}
if($lastexitcode -gt 0) {{
    if($continueOnError) {{
        Write-Warning ""Exit code $lastexitcode""
    }}
    else {{
        throw ""Exit code $lastexitcode""
    }}
}}", _values.ContinueOnError ? "$true": "$false", _cmd));
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var notAlreadyInstalled = string.Format(@"
$progs = Get-WmiObject -Class Win32_Product | Select-Object -Property Name

	foreach($prog in $progs){{
		if($prog.Name -eq ""{0}""){{
            return $false
		}}
	}}
	return $true
", _packageId);

            server.OnlyIf(notAlreadyInstalled).Install.Msi(_packageName, new Uri(_packageUrl));
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var notAlreadyInstalled = string.Format(@"
            $progs = Get-WmiObject -Class Win32_Product | Select-Object -Property Name

            foreach($prog in $progs){{
            if($prog.Name -eq ""{0}""){{
            return $false
            }}
            }}
            return $true
            ", _packageId);

            server.OnlyIf(notAlreadyInstalled).Install.Msi(_packageName, new Uri(_packageUrl));
        }
Example #41
0
        public override void Configure(IOfferRemoteComposition server)
        {
            switch (_sourceType)
            {
            case FileSourceType.File:
                InstallExecutableFromFile(server, _srcExecutableFilePath, _exeParams);
                break;

            case FileSourceType.Url:
                InstallExecutableFromUri(server, _srcExecutableUri, _exeParams);
                break;

            default:
                throw new ConDepInstallationFailureException("Invalid fine source type");
            }
        }
Example #42
0
        public override void Configure(IOfferRemoteComposition server)
        {
            switch (_srcType)
            {
            case FileSourceType.File:
                InstallMsiFromFile(server, _srcMsiFilePath);
                break;

            case FileSourceType.Url:
                InstallMsiFromUrl(server, _srcMsiUri);
                break;

            default:
                throw new Exception("Source type unknown");
            }
        }
Example #43
0
        public override void Configure(IOfferRemoteComposition server)
        {
            string libImport = "";

            //var script = AddExitCodeHandlingToScript(DestinationPath);
            //var filePath = CreateScriptFile(script);
            //var destFilePath = CopyScriptToDestination(server, filePath);
            //ExecuteScriptOnDestination(server, destFilePath);

            if (RequireRemoteLib)
            {
                server.Deploy.File(Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "ConDep.Remote.dll"), @"%temp%\ConDep.Remote.dll");
                libImport = "Add-Type -Path \"" + @"%temp%\ConDep.Remote.dll" + "\";";
            }
            //elseif($Error.Count -gt 0) {{ Write-Error $Error[0]; exit 1; }}
            server.ExecuteRemote.DosCommand(string.Format(@"powershell.exe -noprofile -InputFormat none -Command ""& {{ set-executionpolicy remotesigned -force; $ErrorActionPreference='stop'; Import-Module $env:temp\ConDep\{0}\PSScripts\ConDep; {1}{2}; if(!$?) {{ exit 1; }} else {{ exit $LASTEXITCODE; }} }}""", ConDepGlobals.ExecId, libImport, _command), o => o.ContinueOnError(ContinueOnError).WaitIntervalInSeconds(WaitIntervalInSeconds).RetryAttempts(RetryAttempts));
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var options = BuildOptions(_options);

            server.Execute.PowerShell(string.Format(@"
function ConDep-ChocoPackageExist($name, $version = $null) {{
    $name = $name.ToLower().Trim()
    $result = choco search $($name) --local-only
	$resultArray = ($result -split '[\r\n]') |? {{$_}}
	$packages = @{{}}

     foreach($item in $resultArray) {{
         $line = $item.Trim() -split ""\s+""
         if($line.Count -eq 2) {{
           $package = New-Object PSObject -Property @{{
               Name = $line[0].ToLower().Trim()
               Version = $line[1].substring(1)
           }}

           $packages.Add($line[0].ToLower().Trim(), $package)
         }}
    }}

    $foundPackage = $packages[$name]

    if(!$foundPackage) {{ return $false }}

    if($version) {{
        return ($version -eq $foundPackage.Version)
    }}

    return $false
}}

$package = ""{0}""

if((ConDep-ChocoPackageExist $package)) {{
    write-host ""Package $package allready installed.""
}}
else {{
    choco install $package {1}
}}
", _packageName, options));
        }
Example #45
0
        public override void Configure(IOfferRemoteComposition server, IOfferInfrastructure require)
        {
            var appPoolOptions = "$appPoolOptions = $null;";

            if (_appPoolOptions != null)
            {
                appPoolOptions = string.Format("$appPoolOptions = @{{Enable32Bit=${0}; IdentityUsername='******'; IdentityPassword='******'; IdleTimeoutInMinutes={3}; LoadUserProfile=${4}; ManagedPipeline={5}; NetFrameworkVersion={6}; RecycleTimeInMinutes={7}}};"
                                               , _appPoolOptions.Enable32Bit.HasValue ? _appPoolOptions.Enable32Bit.Value.ToString() : "false"
                                               , _appPoolOptions.IdentityUsername
                                               , _appPoolOptions.IdentityPassword
                                               , _appPoolOptions.IdleTimeoutInMinutes.HasValue ? _appPoolOptions.IdleTimeoutInMinutes.Value.ToString(CultureInfo.InvariantCulture.NumberFormat) : "$null"
                                               , _appPoolOptions.LoadUserProfile.HasValue ? _appPoolOptions.LoadUserProfile.Value.ToString() : "false"
                                               , _appPoolOptions.ManagedPipeline.HasValue ? "'" + _appPoolOptions.ManagedPipeline.Value + "'" : "$null"
                                               , _appPoolOptions.NetFrameworkVersion == null ? "$null" : ("'" + _appPoolOptions.NetFrameworkVersion + "'")
                                               , _appPoolOptions.RecycleTimeInMinutes.HasValue ? _appPoolOptions.RecycleTimeInMinutes.Value.ToString(CultureInfo.InvariantCulture.NumberFormat) : "$null"
                                               );
            }
            server.ExecuteRemote.PowerShell(string.Format(@"{0} New-ConDepAppPool '{1}' $appPoolOptions;", appPoolOptions, _appPoolName), psOptions => psOptions.WaitIntervalInSeconds(30));
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            if (_copyCertFromFile)
            {
                var cert = new X509Certificate2(_certFile);
                ConfigureCertInstall(server, cert);
            }
            else
            {
                var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                try
                {
                    var certs = new X509Certificate2Collection();

                    if (_certFriendlyName != null)
                    {
                        certs.AddRange(store.Certificates.Cast <X509Certificate2>().Where(cert => cert.FriendlyName == _certFriendlyName).ToArray());
                    }
                    else
                    {
                        certs.AddRange(store.Certificates.Find(_findType, _searchString, true));
                    }

                    if (certs.Count != 1)
                    {
                        if (certs.Count < 1)
                        {
                            throw new ConDepCertificateNotFoundException("Certificate not found");
                        }

                        throw new ConDepCertificateDuplicationException("More than one certificate found in search");
                    }

                    ConfigureCertInstall(server, certs[0]);
                }
                finally
                {
                    store.Close();
                }
            }
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            server.Configure
            .Windows(win =>
            {
                win.InstallFeature("Web-Server");
                win.InstallFeature("Web-WebServer");

                foreach (var feature in _featuresToAdd)
                {
                    win.InstallFeature(feature);
                }

                foreach (var feature in _featuresToRemove)
                {
                    win.UninstallFeature(feature);
                }
            });
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            server.Configure
                .Windows(win =>
                {
                    win.InstallFeature("Web-Server");
                    win.InstallFeature("Web-WebServer");

                    foreach (var feature in _featuresToAdd)
                    {
                        win.InstallFeature(feature);
                    }

                    foreach (var feature in _featuresToRemove)
                    {
                        win.UninstallFeature(feature);
                    }
                });
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var options = BuildOptions(_options);
            server.Execute.PowerShell(string.Format(@"
            function ConDep-ChocoPackageExist($name, $version = $null) {{
            $name = $name.ToLower().Trim()
            $result = choco search $($name) --local-only
            $resultArray = ($result -split '[\r\n]') |? {{$_}}
            $packages = @{{}}

             foreach($item in $resultArray) {{
             $line = $item.Trim() -split ""\s+""
             if($line.Count -eq 2) {{
               $package = New-Object PSObject -Property @{{
               Name = $line[0].ToLower().Trim()
               Version = $line[1].substring(1)
               }}

               $packages.Add($line[0].ToLower().Trim(), $package)
             }}
            }}

            $foundPackage = $packages[$name]

            if(!$foundPackage) {{ return $false }}

            if($version) {{
            return ($version -eq $foundPackage.Version)
            }}

            return $false
            }}

            $package = ""{0}""

            if((ConDep-ChocoPackageExist $package)) {{
            write-host ""Package $package allready installed.""
            }}
            else {{
            choco install $package {1}
            }}
            ", _packageName, options));
        }
Example #50
0
        public override void Configure(IOfferRemoteComposition server, IOfferInfrastructure require)
        {
            var appPoolOptions = "$appPoolOptions = $null;";

            if(_appPoolOptions != null)
            {
                appPoolOptions = string.Format("$appPoolOptions = @{{Enable32Bit=${0}; IdentityUsername='******'; IdentityPassword='******'; IdleTimeoutInMinutes={3}; LoadUserProfile=${4}; ManagedPipeline={5}; NetFrameworkVersion={6}; RecycleTimeInMinutes={7}}};"
                    , _appPoolOptions.Enable32Bit.HasValue ? _appPoolOptions.Enable32Bit.Value.ToString() : "false"
                    , _appPoolOptions.IdentityUsername
                    , _appPoolOptions.IdentityPassword
                    , _appPoolOptions.IdleTimeoutInMinutes.HasValue ? _appPoolOptions.IdleTimeoutInMinutes.Value.ToString(CultureInfo.InvariantCulture.NumberFormat) : "$null"
                    , _appPoolOptions.LoadUserProfile.HasValue ? _appPoolOptions.LoadUserProfile.Value.ToString() : "false"
                    , _appPoolOptions.ManagedPipeline.HasValue ? "'" + _appPoolOptions.ManagedPipeline.Value + "'" : "$null"
                    , _appPoolOptions.NetFrameworkVersion == null ? "$null" : ("'" + _appPoolOptions.NetFrameworkVersion +"'")
                    , _appPoolOptions.RecycleTimeInMinutes.HasValue ? _appPoolOptions.RecycleTimeInMinutes.Value.ToString(CultureInfo.InvariantCulture.NumberFormat) : "$null"
                    );
            }
            server.ExecuteRemote.PowerShell(string.Format(@"{0} New-ConDepAppPool '{1}' $appPoolOptions;", appPoolOptions, _appPoolName), psOptions => psOptions.WaitIntervalInSeconds(30));
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            if (_copyCertFromFile)
            {
                var cert = new X509Certificate2(_certFile);
                ConfigureCertInstall(server, cert);
            }
            else
            {
                var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                try
                {
                    var certs = new X509Certificate2Collection();

                    if (_certFriendlyName != null)
                    {
                        certs.AddRange(store.Certificates.Cast<X509Certificate2>().Where(cert => cert.FriendlyName == _certFriendlyName).ToArray());
                    }
                    else
                    {
                        certs.AddRange(store.Certificates.Find(_findType, _searchString, true));
                    }

                    if (certs.Count != 1)
                    {
                        if (certs.Count < 1)
                            throw new ConDepCertificateNotFoundException("Certificate not found");

                        throw new ConDepCertificateDuplicationException("More than one certificate found in search");
                    }

                    ConfigureCertInstall(server, certs[0]);
                }
                finally
                {
                    store.Close();
                }
            }
        }
Example #52
0
        public override void Configure(IOfferRemoteComposition server)
        {
            var options = BuildOptions(_options);

            server.Execute.PowerShell(string.Format(@"
function choco-package-installed($name, $version = $null) {{
    $result = choco version $($name.Trim()) -localonly

    if(!$?) {{ return $false }}    
    if(!$version) {{ return $true }}

	$resultArray = ($result -split '[\r\n]') |? {{$_}}
	$packages = @{{}}

    foreach($item in $resultArray) {{
        $line = $item.Trim() -split ""\s+""
        if($line.Count -eq 2) {{
            $packages.Add($line[0].ToLower().Trim(), $line[1].ToLower().Trim())
        }}
    }}

    $packageVersion = $packages[$($name.Trim().ToLower())]

    if($packageVersion -eq $null) {{ return $false }}

    return $packageVersion.ToLower().Trim() -eq $version.ToLower().Trim()
}}

$packageNames = ""{0}"" -split "" ""

foreach($package in $packageNames) {{
    if(!(choco-package-installed $package)) {{
        choco install $package {1}
    }}
    else {{
        write-host ""Package $package allready installed.""
    }}
}}
", string.Join(" ", _packageNames), options));
        }
Example #53
0
        public override void Configure(IOfferRemoteComposition server, IOfferInfrastructure require)
        {
            var psCommand = string.Format("Set-Location IIS:\\AppPools; try {{ Remove-WebAppPool '{0}' }} catch {{ }}; $newAppPool = New-WebAppPool '{0}'; ", _appPoolName);

            if (_appPoolOptions != null)
            {
                psCommand += _appPoolOptions.Enable32Bit != null ? string.Format("$newAppPool.enable32BitAppOnWin64 = {0}; ", _appPoolOptions.Enable32Bit.Value ? "$true" : "$false") : "";
                psCommand += _appPoolOptions.IdentityUsername != null ? string.Format("$newAppPool.processModel.identityType = 'SpecificUser'; $newAppPool.processModel.username = '******'; $newAppPool.processModel.password = '******'; ", _appPoolOptions.IdentityUsername, _appPoolOptions.IdentityPassword) : "";
                psCommand += _appPoolOptions.IdleTimeoutInMinutes != null ? string.Format("$newAppPool.processModel.idleTimeout = [TimeSpan]::FromMinutes({0}); ", _appPoolOptions.IdleTimeoutInMinutes) : "";
                psCommand += _appPoolOptions.LoadUserProfile != null ? string.Format("$newAppPool.processModel.loadUserProfile = {0}; ", _appPoolOptions.LoadUserProfile.Value ? "$true" : "$false") : "";
                psCommand += _appPoolOptions.ManagedPipeline != null ? string.Format("$newAppPool.managedPipelineMode = '{0}'; ", _appPoolOptions.ManagedPipeline) : "";
                psCommand += _appPoolOptions.NetFrameworkVersion != null ? string.Format("$newAppPool.managedRuntimeVersion = '{0}'; ", ExtractNetFrameworkVersion()) : "";
                psCommand += _appPoolOptions.RecycleTimeInMinutes != null ? string.Format("$newAppPool.recycling.periodicrestart.time = [TimeSpan]::FromMinutes({0}); ", _appPoolOptions.RecycleTimeInMinutes) : "";
            }

            psCommand += "$newAppPool | set-item;";
            string appPoolOptions;

            if(_appPoolOptions != null)
            {
                appPoolOptions = string.Format("$appPoolOptions = @{{Enable32Bit=${0}; IdentityUsername='******'; IdentityPassword='******'; IdleTimeoutInMinutes={3}; LoadUserProfile=${4}; ManagedPipeline={5}; NetFrameworkVersion={6}; RecycleTimeInMinutes={7}}};"
                    , _appPoolOptions.Enable32Bit.HasValue ? _appPoolOptions.Enable32Bit.Value.ToString() : "false"
                    , _appPoolOptions.IdentityUsername
                    , _appPoolOptions.IdentityPassword
                    , _appPoolOptions.IdleTimeoutInMinutes.HasValue ? _appPoolOptions.IdleTimeoutInMinutes.Value.ToString(CultureInfo.InvariantCulture.NumberFormat) : "$null"
                    , _appPoolOptions.LoadUserProfile.HasValue ? _appPoolOptions.LoadUserProfile.Value.ToString() : "false"
                    , _appPoolOptions.ManagedPipeline.HasValue ? "'" + _appPoolOptions.ManagedPipeline.Value + "'" : "$null"
                    , _appPoolOptions.NetFrameworkVersion.HasValue ? "'" + ExtractNetFrameworkVersion() + "'" : "$null"
                    , _appPoolOptions.RecycleTimeInMinutes.HasValue ? _appPoolOptions.RecycleTimeInMinutes.Value.ToString(CultureInfo.InvariantCulture.NumberFormat) : "$null"
                    );
            }
            else
            {
                appPoolOptions = "$appPoolOptions = $null;";
            }
            server.ExecuteRemote.PowerShell(string.Format(@"Import-Module $env:temp\ConDepPowerShellScripts\ConDep; {0} New-ConDepAppPool '{1}' $appPoolOptions;", appPoolOptions, _appPoolName), psOptions => psOptions.WaitIntervalInSeconds(30));
        }
        public override void Configure(IOfferRemoteComposition server)
        {
            var dest = "$env:temp";

            if (_values != null && !string.IsNullOrWhiteSpace(_values.TargetDir))
            {
                dest = _values.TargetDir;
            }

            var uri = new Uri(_url);
            var fileName = Path.GetFileName(uri.AbsolutePath);
            var destFile = Path.Combine(dest, fileName);

            server.Execute.PowerShell(string.Format(@"
            $path = $ExecutionContext.InvokeCommand.ExpandString(""{1}"")

            if((Test-Path $path)) {{
            write-host 'File allready exist. Skipping.'
            }}
            else {{
            $client = new-object System.Net.WebClient
            $client.DownloadFile(""{0}"", $path )
            }}", _url, destFile));
        }
 protected void ConfigureServiceFailure(IOfferRemoteComposition server)
 {
     var serviceFailureCommand = _values.GetServiceFailureCommand(_serviceName);
     if (!string.IsNullOrWhiteSpace(serviceFailureCommand)) server.ExecuteRemote.DosCommand(serviceFailureCommand);
 }
 protected abstract void ConfigureInstallService(IOfferRemoteComposition server);
 protected void ConfigureDeployment(IOfferRemoteComposition server)
 {
     server.Deploy.Directory(_sourceDir, _destDir);
 }
 public abstract void Configure(IOfferRemoteComposition server);
 public override void Configure(IOfferRemoteComposition server)
 {
     server.Execute.DosCommand(string.Format(@"%ProgramData%\chocolatey\chocolateyinstall\tools\7za.exe x -y -o""{1}"" ""{0}""", _filePath, _destPath));
 }
Example #60
0
        public override void Configure(IOfferRemoteComposition server)
        {
            string libImport = "";

            //var script = AddExitCodeHandlingToScript(DestinationPath);
            //var filePath = CreateScriptFile(script);
            //var destFilePath = CopyScriptToDestination(server, filePath);
            //ExecuteScriptOnDestination(server, destFilePath);

            if(RequireRemoteLib)
            {
                server.Deploy.File(Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "ConDep.Remote.dll"), @"%temp%\ConDep.Remote.dll");
                libImport = "Add-Type -Path \"" + @"%temp%\ConDep.Remote.dll" + "\";";
            }
            //elseif($Error.Count -gt 0) {{ Write-Error $Error[0]; exit 1; }}
            server.ExecuteRemote.DosCommand(string.Format(@"powershell.exe -noprofile -InputFormat none -Command ""& {{ set-executionpolicy remotesigned -force; $ErrorActionPreference='stop'; Import-Module $env:temp\ConDep\{0}\PSScripts\ConDep; {1}{2}; if(!$?) {{ exit 1; }} else {{ exit $LASTEXITCODE; }} }}""", ConDepGlobals.ExecId, libImport, _command), o => o.ContinueOnError(ContinueOnError).WaitIntervalInSeconds(WaitIntervalInSeconds).RetryAttempts(RetryAttempts));
        }