Ejemplo n.º 1
0
 public static ActionResult CheckServiceControlUrl(Session session)
 {
     Log(session, "Begin custom action CheckServiceControlUrl");
     var url = session.Get("INST_URI");
     session.Set("VALID_CONTROL_URL", UrlIsValid(url,session) ? "TRUE" : "FALSE");
     Log(session, "End custom action CheckServiceControlUrl");
     return ActionResult.Success;
 }
Ejemplo n.º 2
0
        public static ActionResult ReadForwardAuditMessagesFromConfig(Session session)
        {
            try
            {
                if (session.CustomActionData.Keys.Count != 1)
                {
                    Log(session, "ReadForwardAuditMessagesFromConfig custom action requires a single property name to be passed in the CustomActionData.  The result will passed to that property");
                    return ActionResult.Failure;
                }

                var outputProperty = session.CustomActionData.Keys.First();

                const string ServiceControlRegKey = @"SOFTWARE\ParticularSoftware\ServiceControl";
                var targetPath = session.Get("APPDIR");
                var configPath = Path.Combine(targetPath, @"ServiceControl.exe.config");
                var entryValue = "null";

                // Try to get value from existing config
                if (File.Exists(configPath))
                {
                    var configDoc = XDocument.Load(configPath);
                    var entry = configDoc.XPathSelectElement(@"/configuration/appSettings/add[@key='ServiceControl/ForwardAuditMessages']");
                    entryValue = (entry != null) ? entry.Attribute("value").Value : "null";
                }

                // Fallback to getting value from registry.
                if (!String.IsNullOrWhiteSpace(entryValue))
                {
                    var key = Registry.LocalMachine.OpenSubKey(ServiceControlRegKey, RegistryKeyPermissionCheck.Default);
                    if (key != null)
                    {
                        entryValue = (string) key.GetValue("ForwardAuditMessages", "null");
                    }
                }

                entryValue = entryValue.ToLower();
                switch (entryValue)
                {
                    case "true"  :
                    case "false" :
                        session.Set(outputProperty, entryValue);
                        break;
                    default:
                        session.Set(outputProperty,"null");
                        break;
                }
                return ActionResult.Success;
            }
            catch (Exception ex)
            {
                Log(session, "ReadForwardAuditMessagesFromConfig failed - {0}", ex);
                return ActionResult.Failure;
            }
        }
Ejemplo n.º 3
0
        public static ActionResult ContactServiceControl(Session session)
        {
            Log(session, "Begin custom action ContactServiceControl");
            // getting URL from property
            var url = session.Get("INST_URI");
            var connectionSuccessful = false;
            try
            {
                if (url == null)
                {
                    return ActionResult.Success;
                }

                var request = WebRequest.Create(url);
                request.Timeout = 2000;
                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    if (response == null)
                    {
                        throw new Exception("No response");
                    }

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception(response.StatusDescription);
                    }
                    var version = response.Headers["X-Particular-Version"];
                    if (!string.IsNullOrEmpty(version))
                    {
                        session.Set("REPORTED_VERSION", version.Split(' ').First());
                    }
                }

                connectionSuccessful = true;
            }
            catch (Exception ex)
            {
                Log(session, ex.ToString());
            }
            session.Set("CONTACT_SERVICECONTROL", connectionSuccessful ? "TRUE" : "FALSE");
            Log(session, "End custom action ContactServiceControl");
            return ActionResult.Success;
        }
Ejemplo n.º 4
0
 public static ActionResult CheckPulsePort(Session session)
 {
     try
     {
         Log(session, "Start custom action CheckPulsePort");
         var port = session.Get("INST_PORT_PULSE");
         UInt16 portNumber;
         if (UInt16.TryParse(port, out portNumber))
         {
             // Port number 49152 and above should no be used http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
             if (portNumber < 49152)
             {
                 session.Set("VALID_PORT", "TRUE");
                 return ActionResult.Success;
             }
         }
         session.Set("VALID_PORT", "FALSE");
         return ActionResult.Success;
     }
     finally
     {
         Log(session, "End custom action CheckPulsePort");
     }
 }
Ejemplo n.º 5
0
        public static ActionResult SetUrlAcl(Session session)
        {
            Log(session, "Start custom action SetUrlAcl");
               var port = session.Get("INST_PORT_PULSE");
               var aclUrl =  string.Format("http://+:{0}/", port);

               RunNetsh(string.Format("http del urlacl url={0}", aclUrl));
               // sddl=D:(A;;GX;;;WD) maps to the same as setting user=Everyone
               // user=everyone fails if the OS language is not English,  localised lookup of NTAccount fails as MSI is set to English US
               var addUrlAclCommand = string.Format("http add urlacl url={0} sddl=D:(A;;GX;;;WD)", aclUrl);
               var exitCode = RunNetsh(addUrlAclCommand);
               if (exitCode != 0)
               {
                Log(session, string.Format("Error: 'netsh.exe {0}' returned {1}", addUrlAclCommand, exitCode));
                Log(session, "End custom action SetUrlAcl");
                return ActionResult.Failure;
            }
            Log(session, string.Format("Success :Executed: 'netsh.exe {0}'", addUrlAclCommand));
            Log(session, "End custom action SetUrlAcl");
            return ActionResult.Success;
        }
Ejemplo n.º 6
0
        public static ActionResult ReadServiceControlUrlFromConfigJS(Session session)
        {
            try
            {
                Log(session, "Start custom action ReadServiceControlUrlFromConfigJS");
                var targetPath = session.Get("APPDIR");
                var configJsPath = Path.Combine(targetPath, @"app\config.js");
                var uri = @"http://*****:*****@"service_control_url:\s*'(?<sc_uri>.*)'", RegexOptions.IgnoreCase);
                    var matches = pattern.Match(File.ReadAllText(configJsPath));
                    if (matches.Success)
                    {
                        uri = matches.Groups["sc_uri"].Value;
                        Log(session, string.Format(@"Extracted {0} from existing config.js", uri));
                    }
                    else
                    {
                        Log(session, "No URI found - using default");
                    }
                }
                else
                {
                    Log(session, string.Format("File not found {0}", configJsPath));
                }
                session.Set("INST_URI", uri);
                return ActionResult.Success;
            }
            finally
            {
                Log(session, "End custom action ReadServiceControlUrlFromConfigJS");
            }
        }
Ejemplo n.º 7
0
 public static ActionResult ValidateForwardAuditMessages(Session session)
 {
     var forwardAuditMessages = session.Get("FORWARDAUDITMESSAGES");
     switch (forwardAuditMessages)
     {
         case "true":
         case "false":
             return ActionResult.Success;
     }
     Log(session, "A required settings has not been provided. ForwardAuditMessages must be explicitly set to true or false when installing via unattended mode. e.g. 'Particular.ServiceControl.exe /quiet ForwardAuditMessages=false'");
     return ActionResult.Failure;
 }