Пример #1
0
        public void Application_OnError(Object sender , EventArgs e)
        {
            //HttpApplication application = (HttpApplication)sender;
            //HttpContext context = application.Context;
            ////if (context.Server.GetLastError().GetBaseException() is MyException)
            //{
            //    //MyException ex = (MyException) context.Server.GetLastError().GetBaseException();
            //    context.Response.Write("<html><body style=\"font-size:14px;\">");
            //    context.Response.Write("Error:<br />");
            //    context.Response.Write("<textarea name=\"errormessage\" style=\"width:80%; height:200px; word-break:break-all\">");
            //    context.Response.Write(System.Web.HttpUtility.HtmlEncode(context.Server.GetLastError().ToString()));
            //    context.Response.Write("</textarea>");
            //    context.Response.Write("</body></html>");
            //    context.Response.End();
            //}
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;

            CSException csException = context.Server.GetLastError() as CSException;

            if (csException == null)
                csException = context.Server.GetLastError().GetBaseException() as CSException;

            try
            {
                if (csException != null)
                {
                    switch (csException.ExceptionType)
                    {
                        case CSExceptionType.UserInvalidCredentials:
                        case CSExceptionType.AccessDenied:
                        case CSExceptionType.AdministrationAccessDenied:
                        case CSExceptionType.ModerateAccessDenied:
                        case CSExceptionType.PostDeleteAccessDenied:
                        case CSExceptionType.PostProblem:
                        case CSExceptionType.UserAccountBanned:
                        case CSExceptionType.ResourceNotFound:
                        case CSExceptionType.UserUnknownLoginError:
                        case CSExceptionType.SectionNotFound:
                            csException.Log();
                            break;
                    }
                }
                else
                {
                    Exception ex = context.Server.GetLastError();
                    if (ex.InnerException != null)
                        ex = ex.InnerException;

                    csException = new CSException(CSExceptionType.UnknownError, ex.Message, context.Server.GetLastError());

                    System.Data.SqlClient.SqlException sqlEx = ex as System.Data.SqlClient.SqlException;
                    if (sqlEx == null || sqlEx.Number != -2) //don't log time outs
                        csException.Log();
                }
            }
            catch { } //not much to do here, but we want to prevent infinite looping with our error handles

            CSEvents.CSException(csException);
        }
Пример #2
0
        public static string EmoticonTransforms(string formattedPost)
        {
            // remove some overhead if this is turned off
            if (!CSContext.Current.SiteSettings.EnableEmoticons)
                return formattedPost;

            try {
                // Load the emoticon transform table
                //
                ArrayList emoticonTxTable = Smilies.GetSmilies();

                const string imgFormat = "<img src=\"{0}{1}\" alt=\"{2}\" />";

                // EAD 6/27/2004: Changed to loop through twice.
                // Once for brackets first, so to capture the Party emoticon
                // (special emoticons that REQUIRE brackets), so not to replace
                // with other non-bracket icons. Less efficient yes, but captures
                // all emoticons properly.
                //
                string smileyPattern	= "";
                string replacePattern	= "";
                RegexOptions options	= RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Multiline ;
                string forumHomePath = Globals.GetSiteUrls().Emoticon;

                foreach ( Smiley smiley in emoticonTxTable ) {
                    smileyPattern	= string.Format(@"\[{0}\]", Regex.Escape(smiley.SmileyCode) );
                    replacePattern	= string.Format(imgFormat, forumHomePath, smiley.SmileyUrl, smiley.SmileyText + " [[SmileyCode]]");

                    formattedPost = Regex.Replace( formattedPost, smileyPattern, replacePattern, options );

                    if ( smiley.IsSafeWithoutBrackets() )
                    {
                        formattedPost = Regex.Replace( formattedPost, Regex.Escape(smiley.SmileyCode),
                                replacePattern,
                                options );
                    }

                    // If the smiley code contains a < or >, check to see if it was HtmlEncoded in the body
                    if(smiley.SmileyCode.IndexOfAny( new char[] { '<', '>', '&' }) != -1)
                    {
                        try
                        {
                            smileyPattern	= string.Format(@"\[{0}\]", Regex.Escape(HttpContext.Current.Server.HtmlEncode(smiley.SmileyCode)) );
                            formattedPost = Regex.Replace( formattedPost, smileyPattern, replacePattern, options );

                            if(smiley.IsSafeWithoutBrackets())
                            {
                                formattedPost = Regex.Replace( formattedPost, Regex.Escape(HttpContext.Current.Server.HtmlEncode(smiley.SmileyCode)),
                                    replacePattern,
                                    options );
                            }
                        }
                        catch(NullReferenceException) { }	// If we are outside of a web-context, referencing HttpContext.Current could throw a null ref.
                    }

                    // Finally, look for [SmileyCode] to place the smiley's code back in there (mostly for in the alt tags)
                    // If the smiley was actually there, it could end up getting mistaken for another smiley... ie, [:)]
                    // would get an alt tag of "Smile [:)]", it'll then search for the non-bracket version, and see :) and treat it as another instance
                    formattedPost = Regex.Replace( formattedPost, @"\[SmileyCode\]", smiley.SmileyCode, options );

                }

                return formattedPost;
            } catch( Exception e ) {
                CSException ex = new CSException( CSExceptionType.UnknownError, "Could not transform smilies in the post.", e );
                ex.Log();

                return formattedPost;
            }
        }
Пример #3
0
        /// <summary>
        /// Enables the interation of all current SiteSettings
        /// </summary>
        /// <param name="iter">Meth which takes a single parameter SettingsID</param>
        public static void IterateSiteSettings(SiteSettingsListIterator iter)
        {
            //            Hashtable ht = SiteSettingsManager.GetActiveSiteSettings();
            //            if(ht == null || ht.Count == 0)
            //                return;
            //
            //
            //			string[] keys = new string[ht.Count];
            //			ht.Keys.CopyTo(keys, 0);

            int[] settingIDs = SiteSettingsManager.GetSettingIDs();
            for(int i = 0; i < settingIDs.Length; i++)
            {

                try
                {
                    iter(settingIDs[i]);

                }
                catch(Exception ex)
                {
                    CSException csException = new CSException(CSExceptionType.UnknownError,string.Format("Iterator Failed. Type {0}. Method {1}. Reason {2}",iter.Method.DeclaringType, iter.Method.Name,ex.Message));
                    csException.Log(settingIDs[i]);
                    throw;
                }
            }
        }
Пример #4
0
Файл: Emails.cs Проект: pcstx/OA
        public static void SendQueuedEmails(int failureInterval, int maxNumberOfTries)
        {
            CommonDataProvider dp = CommonDataProvider.Instance();
            CSConfiguration csConfig = CSConfiguration.GetConfig();

            // test to see if this server is disabled for sending email
            //
            if (csConfig.IsEmailDisabled)
                return;

            Hashtable sites = SiteSettingsManager.GetActiveSiteSettings();
            if(sites == null || sites.Count == 0)
                return;

            // Copy the keys to another array to avoid getting a collection modified error
            string[] keys = new string[sites.Count];
            sites.Keys.CopyTo(keys, 0);

            foreach(string key in keys)
            {
                SiteSettings site = sites[key] as SiteSettings;
                if(site == null || !site.EnableEmail)
                    continue;

                ArrayList emails = dp.EmailDequeue(site.SettingsID);
                ArrayList failure = new ArrayList();

                SmtpMail.SmtpServer = site.SmtpServer;
                string username = site.SmtpServerUserName;
                string password = site.SmtpServerPassword;

                int sentCount	= 0;
                int totalSent	= 0;
                short connectionLimit = csConfig.SmtpServerConnectionLimit;
                foreach (EmailTemplate m in emails)
                {
                    try
                    {
                        //for SMTP Authentication
                        if (site.SmtpServerRequiredLogin)
                        {
                            m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" ); //basic authentication
                            m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username ); //set your username here
                            m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password ); //set your password here
                        }

                        // For Html emails, this resolves the complete paths for images and links.
                        // Should not effect non-Html emails via RFC-2110.
                        //
                        // EAD 1/14/2005: Commented out until we can access the forumContext from a background thread.
                        //m.Fields.Add("Content-Base", Globals.FullPath(Globals.GetSiteUrls().Home) );
                        //m.Fields.Add("Content-Location", Globals.FullPath(Globals.GetSiteUrls().Home) );
                        m.Headers.Add("X-CS-EmailID", m.EmailID.ToString());
                        m.Headers.Add("X-CS-ThreadId", AppDomain.GetCurrentThreadId().ToString());
                        m.Headers.Add("X-CS-Attempts", (m.NumberOfTries + 1).ToString());
                        m.Headers.Add("X-CS-AppDomain", AppDomain.CurrentDomain.FriendlyName);
                        SmtpMail.Send(m);

                        // (Ken) Moved the delete command to here
                        //       If a number of emails were sent, the command to delete them could timeout and duplicates would be sent on the next run
                        dp.EmailDelete(m.EmailID);

                        if(		connectionLimit != -1 &&	++sentCount >= connectionLimit )
                        {
                            Thread.Sleep( new TimeSpan( 0, 0, 0, 15, 0 ) );
                            sentCount = 0;
                        }
                        // on error, loop so to continue sending other email.
                    }
                    catch( Exception e )
                    {
                        Debug.WriteLine( e.Message + " : " + ( e.InnerException != null ? e.InnerException.Message : String.Empty ) );
                        CSException fe = new CSException( CSExceptionType.EmailUnableToSend, "SendQueuedEmails Failed To: " + m.To, ( e.InnerException != null ? e.InnerException : e ) );
                        fe.Log(site.SettingsID);

                        // Add it to the failure list
                        failure.Add(m.EmailID);
                    }

                    if( site.EmailThrottle > 0 && ++totalSent >= site.EmailThrottle ) {
                        break;
                    }
                }

                if(failure.Count > 0)
                    dp.EmailFailure(failure, failureInterval, maxNumberOfTries);

            }
        }
Пример #5
0
Файл: Roles.cs Проект: pcstx/OA
        public static string[] GetUserRoleNames(string username, bool cacheable)
        {
            string[] roles  = null;
            string key = "UserRoleNames:" + username;

            if(cacheable)
                roles = CSCache.Get(key) as string[];
            else
                CSCache.Remove(key);

            if(roles == null)
            {

                // there is a situation where the cookie may be using an old username, which can cause this call to fail, at this point
                // we're too deep in the call tree to do anything else, so we just need to log the exception and force the
                // user to signout since we're having problems pulling the user's roles from the database
                try{
                    roles = Microsoft.ScalableHosting.Security.Roles.GetRolesForUser(username);

                    if(cacheable)
                        CSCache.Insert(key, roles, 10 * CSCache.MinuteFactor);
                }
                catch( Exception e ) {
                    CSException cse = new CSException( CSExceptionType.RoleNotFound, String.Format("Error while trying to find a role for the user '{0}'. Possible cause is a invalid client cookie or a user rename.", username ), e );
                    cse.Log();

                    FormsAuthentication.SignOut();
                    HttpContext.Current.Response.Redirect( SiteUrls.Instance().Home );
                }
            }

            return roles;
        }
Пример #6
0
        private void Application_AuthenticateRequest(Object source, EventArgs e)
        {
            HttpContext context = HttpContext.Current;
            Provider p = null;
            ExtensionModule module = null;

            // If the installer is making the request terminate early
            if (CSConfiguration.GetConfig().AppLocation.CurrentApplicationType == ApplicationType.Installer)
            {
                return;
            }

            // Only continue if we have a valid context
            //
            if ((context == null) || (context.User == null))
                return;

            try
            {
                // Logic to handle various authentication types
                //
                switch (context.User.Identity.GetType().Name.ToLower())
                {

                    // Microsoft passport
                    case "passportidentity":
                        p = (Provider)CSConfiguration.GetConfig().Extensions["PassportAuthentication"];
                        module = ExtensionModule.Instance(p);
                        if (module != null)
                            module.ProcessRequest();
                        else
                            goto default;
                        break;

                    // Windows
                    case "windowsidentity":
                        p = (Provider)CSConfiguration.GetConfig().Extensions["WindowsAuthentication"];
                        module = ExtensionModule.Instance(p);
                        if (module != null)
                            module.ProcessRequest();
                        else
                            goto default;
                        break;

                    // Forms
                    case "formsidentity":
                        p = (Provider)CSConfiguration.GetConfig().Extensions["FormsAuthentication"];
                        module = ExtensionModule.Instance(p);
                        if (module != null)
                            module.ProcessRequest();
                        else
                            goto default;
                        break;

                    // Custom
                    case "customidentity":
                        p = (Provider)CSConfiguration.GetConfig().Extensions["CustomAuthentication"];
                        module = ExtensionModule.Instance(p);
                        if (module != null)
                            module.ProcessRequest();
                        else
                            goto default;
                        break;

                    default:
                        CSContext.Current.UserName = context.User.Identity.Name;
                        break;

                }

            }
            catch (Exception ex)
            {
                CSException forumEx = new CSException(CSExceptionType.UnknownError, "Error in AuthenticateRequest", ex);
                forumEx.Log();

                throw forumEx;
            }

            //			// Get the roles the user belongs to
            //			//
            //			Roles roles = new Roles();
            //			roles.GetUserRoles();
        }