Exemplo n.º 1
0
        private void CasAuthenticate(Site site, ref CookieCollection cookies, ref HtmlDocument document)
        {
            // read the parameters we need to know
            var form = document.GetElementbyId("fm1");
            var hidden = document.DocumentNode.Descendants("input").Where(a => a.Attributes["type"].Value == "hidden");

            var parameters = new StringBuilder();

            foreach (var p in hidden)
            {
                parameters.Append(string.Format("{0}={1}&", p.Attributes["name"].Value, p.Attributes["value"].Value));
            }

            var action = form.Attributes["action"];
            var username = ConfigurationSettings.AppSettings["username"];
            var password = ConfigurationSettings.AppSettings["password"];

            parameters.Append(string.Format("{0}={1}&", "username", username));
            parameters.Append(string.Format("{0}={1}", "password", password));

            // location to redirect back to the application
            var redirectLocation = string.Empty;
            MakeWebCallWithParameters("https://cas.ucdavis.edu:8443" + action.Value, parameters.ToString(), ref cookies, out redirectLocation);

            // get the ticket
            var ticketUrl = string.Format("https://cas.ucdavis.edu:8443/cas/login?service={0}", redirectLocation);
            var location = string.Empty;
            ErrorTypes errorType;
            MakeWebCall(ticketUrl, false, ref cookies, ref document, out location, out errorType);

            // get the aspx auth id
            var nothing = string.Empty;
            MakeWebCall(location, false, ref cookies, ref document, out nothing, out errorType);
        }
Exemplo n.º 2
0
        private void ErrorResolution(Site site, int statuscode, ErrorTypes errorType)
        {
            if (_restartCodes.Contains(statuscode) && (site.FailureCount < 4 || site.FailureCount % 10 == 0))
            {
                // only notify after 15 minutes
                if (site.FailureCount == 3)
                {
                    // trigger an email about a failed site
                    Console.WriteLine("Admin Intervene ({0}) with error {1}. Failure count {2}", site.Url, errorType.ToString(), site.FailureCount);
                }
                // only attempt a restart for the first few times
                else
                {
                    // try to restart the application pool
                    Console.WriteLine("Attempting restart ({0}).  Failure count {1}", site.Url, site.FailureCount);

                    RestartApplicationPool(site.AppPool);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a webpage and returns the status
        /// </summary>
        /// <param name="url"></param>
        /// <returns>true = good, false = bad</returns>
        private bool CheckSite(Site site, out int status, out ErrorTypes errorType)
        {
            // load the webpage
            try
            {
                var cookies = new CookieCollection();
                var document = new HtmlDocument();

                // make the first call
                var nothing = string.Empty;
                status = MakeWebCall(site.Url, true, ref cookies, ref document, out nothing, out errorType);

                // is cas protected, we need to authenticate
                if (site.AuthenticationType == AuthenticationType.UcdCas && document.GetElementbyId("cas") != null)
                {
                    CasAuthenticate(site, ref cookies, ref document);
                    status = MakeWebCall(site.Url, true, ref cookies, ref document, out nothing, out errorType);
                }

                return status == 200;
            }
            catch (WebException webEx)
            {
                status = (int)((HttpWebResponse)webEx.Response).StatusCode;

                var stream = new StreamReader(webEx.Response.GetResponseStream());
                var page = stream.ReadToEnd();

                if (page.Contains("Cannot open database"))
                {
                    errorType = ErrorTypes.Database;
                }
                else
                {
                    errorType = ErrorTypes.Unknown;
                }
            }

            return false;
        }