Esempio n. 1
0
        //*************************************************************
        public static void auto_reply(int bugid, string from_addr, string short_desc, int projectid)
        {
            string auto_reply_text = Util.get_setting("AutoReplyText", "");

            if (auto_reply_text == "")
            {
                return;
            }

            auto_reply_text = auto_reply_text.Replace("$BUGID$", Convert.ToString(bugid));


            string sql = @"select
						pj_pop3_email_from
						from projects
						where pj_id = $pj"                        ;

            sql = sql.Replace("$pj", Convert.ToString(projectid));

            object project_email = DbUtil.execute_scalar(sql);

            if (project_email == null)
            {
                Util.write_to_log("skipping auto reply because project email is blank");
                return;
            }

            string project_email_string = Convert.ToString(project_email);

            if (project_email_string == "")
            {
                Util.write_to_log("skipping auto reply because project email is blank");
                return;
            }

            // To avoid an infinite loop of replying to emails and then having to reply to the replies!
            if (project_email_string.ToLower() == from_addr.ToLower())
            {
                Util.write_to_log("skipping auto reply because from address is same as project email:" + project_email_string);
                return;
            }

            string outgoing_subject = short_desc + "  ("
                                      + Util.get_setting("TrackingIdString", "DO NOT EDIT THIS:")
                                      + Convert.ToString(bugid) + ")";

            bool use_html_format = (Util.get_setting("AutoReplyUseHtmlEmailFormat", "0") == "1");

            // commas cause trouble
            string cleaner_from_addr = from_addr.Replace(",", " ");

            Email.send_email(      // 4 args
                cleaner_from_addr, // we are responding TO the address we just received email FROM
                project_email_string,
                "",                // cc
                outgoing_subject,
                auto_reply_text,
                use_html_format ? BtnetMailFormat.Html : BtnetMailFormat.Text);
        }
Esempio n. 2
0
        public static int get_bugid_from_subject(ref string subject)
        {
            int bugid = 0;

            // Try to parse out the bugid from the subject line
            string bugidString = Util.get_setting("TrackingIdString", "DO NOT EDIT THIS:");

            int pos = subject.IndexOf(bugidString);

            if (pos >= 0)
            {
                // position of colon
                pos = subject.IndexOf(":", pos);
                pos++;

                // position of close paren
                int pos2 = subject.IndexOf(")", pos);
                if (pos2 > pos)
                {
                    string bugid_string_temp = subject.Substring(pos, pos2 - pos);
                    if (Util.is_int(bugid_string_temp))
                    {
                        bugid = Convert.ToInt32(bugid_string_temp);
                    }
                }
            }

            // maybe a deleted bug?
            if (bugid != 0)
            {
                string sql = "select count(1) from bugs where bg_id = $bg";
                sql = sql.Replace("$bg", Convert.ToString(bugid));
                int bug_count = (int)DbUtil.execute_scalar(sql);
                if (bug_count != 1)
                {
                    subject = subject.Replace(bugidString, "WAS #:");
                    bugid   = 0;
                }
            }

            return(bugid);
        }
Esempio n. 3
0
        ///////////////////////////////////////////////////////////////////////
        public static int get_default_user(int projectid)
        {
            if (projectid == 0)
            {
                return(0);
            }

            string sql = @"select isnull(pj_default_user,0)
					from projects
					where pj_id = $pj"                    ;

            sql = sql.Replace("$pj", Convert.ToString(projectid));
            object obj = DbUtil.execute_scalar(sql);

            if (obj != null)
            {
                return((int)obj);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 4
0
        ///////////////////////////////////////////////////////////////////////
        public static int insert_comment(
            int bugid,
            int this_usid,
            string comment_formated,
            string comment_search,
            string from,
            string cc,
            string content_type,
            bool internal_only)
        {
            if (comment_formated != "")
            {
                string sql = @"
declare @now datetime
set @now = getdate()

insert into bug_posts
(bp_bug, bp_user, bp_date, bp_comment, bp_comment_search, bp_email_from, bp_email_cc, bp_type, bp_content_type,
bp_hidden_from_external_users)
values(
$id,
$us,
@now,
N'$comment_formatted',
N'$comment_search',
N'$from',
N'$cc',
N'$type',
N'$content_type',
$internal)
select scope_identity();";

                if (from != null)
                {
                    // Update the bugs timestamp here.
                    // We don't do it unconditionally because it would mess up the locking.
                    // The edit_bug.aspx page gets its snapshot timestamp from the update of the bug
                    // row, not the comment row, so updating the bug again would confuse it.
                    sql += @"update bugs
						set bg_last_updated_date = @now,
						bg_last_updated_user = $us
						where bg_id = $id"                        ;

                    sql = sql.Replace("$from", from.Replace("'", "''"));
                    sql = sql.Replace("$type", "received");                     // received email
                }
                else
                {
                    sql = sql.Replace("N'$from'", "null");
                    sql = sql.Replace("$type", "comment");                     // bug comment
                }

                sql = sql.Replace("$id", Convert.ToString(bugid));
                sql = sql.Replace("$us", Convert.ToString(this_usid));
                sql = sql.Replace("$comment_formatted", comment_formated.Replace("'", "''"));
                sql = sql.Replace("$comment_search", comment_search.Replace("'", "''"));
                sql = sql.Replace("$content_type", content_type);
                if (cc == null)
                {
                    cc = "";
                }
                sql = sql.Replace("$cc", cc.Replace("'", "''"));
                sql = sql.Replace("$internal", Util.bool_to_string(internal_only));



                return(Convert.ToInt32(DbUtil.execute_scalar(sql)));
            }
            else
            {
                return(0);
            }
        }
Esempio n. 5
0
        ///////////////////////////////////////////////////////////////////////
        public static NewIds insert_bug(
            string short_desc,
            Security security,
            string tags,
            int projectid,
            int orgid,
            int categoryid,
            int priorityid,
            int statusid,
            int assigned_to_userid,
            int udfid,
            string project_custom_dropdown_value1,
            string project_custom_dropdown_value2,
            string project_custom_dropdown_value3,
            string comment_formated,
            string comment_search,
            string from,
            string cc,
            string content_type,
            bool internal_only,
            SortedDictionary <string, string> hash_custom_cols,
            bool send_notifications)
        {
            if (short_desc.Trim() == "")
            {
                short_desc = "[No Description]";
            }

            if (assigned_to_userid == 0)
            {
                assigned_to_userid = Util.get_default_user(projectid);
            }

            string sql = @"insert into bugs
					(bg_short_desc,
					bg_tags,
					bg_reported_user,
					bg_last_updated_user,
					bg_reported_date,
					bg_last_updated_date,
					bg_project,
					bg_org,
					bg_category,
					bg_priority,
					bg_status,
					bg_assigned_to_user,
					bg_user_defined_attribute,
					bg_project_custom_dropdown_value1,
					bg_project_custom_dropdown_value2,
					bg_project_custom_dropdown_value3
					$custom_cols_placeholder1)
					values (N'$short_desc', N'$tags', $reported_user,  $reported_user, getdate(), getdate(),
					$project, $org,
					$category, $priority, $status, $assigned_user, $udf,
					N'$pcd1',N'$pcd2',N'$pcd3' $custom_cols_placeholder2)"                    ;

            sql = sql.Replace("$short_desc", short_desc.Replace("'", "''"));
            sql = sql.Replace("$tags", tags.Replace("'", "''"));
            sql = sql.Replace("$reported_user", Convert.ToString(security.user.usid));
            sql = sql.Replace("$project", Convert.ToString(projectid));
            sql = sql.Replace("$org", Convert.ToString(orgid));
            sql = sql.Replace("$category", Convert.ToString(categoryid));
            sql = sql.Replace("$priority", Convert.ToString(priorityid));
            sql = sql.Replace("$status", Convert.ToString(statusid));
            sql = sql.Replace("$assigned_user", Convert.ToString(assigned_to_userid));
            sql = sql.Replace("$udf", Convert.ToString(udfid));
            sql = sql.Replace("$pcd1", project_custom_dropdown_value1);
            sql = sql.Replace("$pcd2", project_custom_dropdown_value2);
            sql = sql.Replace("$pcd3", project_custom_dropdown_value3);

            if (hash_custom_cols == null)
            {
                sql = sql.Replace("$custom_cols_placeholder1", "");
                sql = sql.Replace("$custom_cols_placeholder2", "");
            }
            else
            {
                string custom_cols_sql1 = "";
                string custom_cols_sql2 = "";

                DataSet ds_custom_cols = Util.get_custom_columns();

                foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
                {
                    string column_name = (string)drcc["name"];

                    // skip if no permission to update
                    if (security.user.dict_custom_field_permission_level[column_name] != Security.PERMISSION_ALL)
                    {
                        continue;
                    }

                    custom_cols_sql1 += ",[" + column_name + "]";

                    string datatype = (string)drcc["datatype"];

                    string custom_col_val = Util.request_to_string_for_sql(
                        hash_custom_cols[column_name],
                        datatype);

                    custom_cols_sql2 += "," + custom_col_val;
                }
                sql = sql.Replace("$custom_cols_placeholder1", custom_cols_sql1);
                sql = sql.Replace("$custom_cols_placeholder2", custom_cols_sql2);
            }



            sql += "\nselect scope_identity()";


            int bugid  = Convert.ToInt32(DbUtil.execute_scalar(sql));
            int postid = Bug.insert_comment(
                bugid,
                security.user.usid,
                comment_formated,
                comment_search,
                from,
                cc,
                content_type,
                internal_only);

            Bug.auto_subscribe(bugid);

            if (send_notifications)
            {
                Bug.send_notifications(Bug.INSERT, bugid, security);
            }

            return(new NewIds(bugid, postid));
        }
Esempio n. 6
0
        ///////////////////////////////////////////////////////////////////////
        public static BugPostAttachment get_bug_post_attachment(int bp_id)
        {
            // Note that this method does not perform any security check.
            // This is left up to the caller.


            string upload_folder = Util.get_upload_folder();
            string sql;
            bool   store_attachments_in_database = (Util.get_setting("StoreAttachmentsInDatabase", "0") == "1");
            int    bugid;
            string file;
            int    content_length;
            string content_type;
            Stream content = null;

            try
            {
                sql = @"select bp_bug, bp_file, bp_size, bp_content_type
						from bug_posts
						where bp_id = $bp"                        ;

                sql = sql.Replace("$bp", Convert.ToString(bp_id));
                using (SqlDataReader reader = DbUtil.execute_reader(sql, CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        bugid          = reader.GetInt32(reader.GetOrdinal("bp_bug"));
                        file           = reader.GetString(reader.GetOrdinal("bp_file"));
                        content_length = reader.GetInt32(reader.GetOrdinal("bp_size"));
                        content_type   = reader.GetString(reader.GetOrdinal("bp_content_type"));
                    }
                    else
                    {
                        throw new Exception("Existing bug post not found.");
                    }
                }

                sql = @"select bpa_content
							from bug_post_attachments
							where bpa_post = $bp"                            ;

                sql = sql.Replace("$bp", Convert.ToString(bp_id));

                object content_object;
                content_object = DbUtil.execute_scalar(sql);

                if (content_object != null && !Convert.IsDBNull(content_object))
                {
                    content = new MemoryStream((byte[])content_object);
                }
                else
                {
                    // Could not find in bug_post_attachments. Try the upload_folder.
                    if (upload_folder == null)
                    {
                        throw new Exception("The attachment could not be found in the database and UploadFolder is not set in web.config.");
                    }

                    string upload_folder_filename = upload_folder + "\\" + bugid + "_" + bp_id + "_" + file;
                    if (File.Exists(upload_folder_filename))
                    {
                        content = new FileStream(upload_folder_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }
                    else
                    {
                        throw new Exception("Attachment not found in database or UploadFolder.");
                    }
                }

                return(new BugPostAttachment(file, content, content_length, content_type));
            }
            catch
            {
                if (content != null)
                {
                    content.Dispose();
                }

                throw;
            }
        }
Esempio n. 7
0
        ///////////////////////////////////////////////////////////////////////
        private static int insert_post_attachment_impl(
            Security security,
            int bugid,
            Stream content,
            int content_length,
            int copy_bpid,
            string file,
            string comment,
            string content_type,
            int parent,
            bool hidden_from_external_users,
            bool send_notifications)
        {
            // Note that this method does not perform any security check nor does
            // it check that content_length is less than MaxUploadSize.
            // These are left up to the caller.


            string upload_folder = Util.get_upload_folder();
            string sql;
            bool   store_attachments_in_database = (Util.get_setting("StoreAttachmentsInDatabase", "0") == "1");
            string effective_file           = file;
            int    effective_content_length = content_length;
            string effective_content_type   = content_type;
            Stream effective_content        = null;

            try
            {
                // Determine the content. We may be instructed to copy an existing
                // attachment via copy_bpid, or a Stream may be provided as the content parameter.

                if (copy_bpid != -1)
                {
                    BugPostAttachment bpa = get_bug_post_attachment(copy_bpid);

                    effective_content        = bpa.content;
                    effective_file           = bpa.file;
                    effective_content_length = bpa.content_length;
                    effective_content_type   = bpa.content_type;
                }
                else
                {
                    effective_content        = content;
                    effective_file           = file;
                    effective_content_length = content_length;
                    effective_content_type   = content_type;
                }

                // Insert a new post into bug_posts.

                sql = @"
declare @now datetime

set @now = getdate()

update bugs
	set bg_last_updated_date = @now,
	bg_last_updated_user = $us
	where bg_id = $bg

insert into bug_posts
	(bp_type, bp_bug, bp_file, bp_comment, bp_size, bp_date, bp_user, bp_content_type, bp_parent, bp_hidden_from_external_users)
	values ('file', $bg, N'$fi', N'$de', $si, @now, $us, N'$ct', $pa, $internal)
	select scope_identity()"    ;

                sql = sql.Replace("$bg", Convert.ToString(bugid));
                sql = sql.Replace("$fi", effective_file.Replace("'", "''"));
                sql = sql.Replace("$de", comment.Replace("'", "''"));
                sql = sql.Replace("$si", Convert.ToString(effective_content_length));
                sql = sql.Replace("$us", Convert.ToString(security.user.usid));

                // Sometimes, somehow, content type is null.  Not sure how.
                sql = sql.Replace("$ct",
                                  effective_content_type != null
                                                ? effective_content_type.Replace("'", "''")
                                                : string.Empty);

                if (parent == -1)
                {
                    sql = sql.Replace("$pa", "null");
                }
                else
                {
                    sql = sql.Replace("$pa", Convert.ToString(parent));
                }
                sql = sql.Replace("$internal", Util.bool_to_string(hidden_from_external_users));

                int bp_id = Convert.ToInt32(DbUtil.execute_scalar(sql));

                try
                {
                    // Store attachment in bug_post_attachments table.

                    if (store_attachments_in_database)
                    {
                        byte[] data       = new byte[effective_content_length];
                        int    bytes_read = 0;

                        while (bytes_read < effective_content_length)
                        {
                            int bytes_read_this_iteration = effective_content.Read(data, bytes_read, effective_content_length - bytes_read);
                            if (bytes_read_this_iteration == 0)
                            {
                                throw new Exception("Unexpectedly reached the end of the stream before all data was read.");
                            }
                            bytes_read += bytes_read_this_iteration;
                        }

                        sql = @"insert into bug_post_attachments
								(bpa_post, bpa_content)
								values (@bp, @bc)"                                ;
                        using (SqlCommand cmd = new SqlCommand(sql))
                        {
                            cmd.Parameters.AddWithValue("@bp", bp_id);
                            cmd.Parameters.Add("@bc", SqlDbType.Image).Value = data;
                            cmd.CommandTimeout = Convert.ToInt32(Util.get_setting("SqlCommand.CommandTimeout", "30"));
                            DbUtil.execute_nonquery(cmd);
                        }
                    }
                    else
                    {
                        // Store attachment in UploadFolder.

                        if (upload_folder == null)
                        {
                            throw new Exception("StoreAttachmentsInDatabase is false and UploadFolder is not set in web.config.");
                        }

                        // Copy the content Stream to a file in the upload_folder.
                        byte[] buffer     = new byte[16384];
                        int    bytes_read = 0;
                        using (FileStream fs = new FileStream(upload_folder + "\\" + bugid + "_" + bp_id + "_" + effective_file, FileMode.CreateNew, FileAccess.Write))
                        {
                            while (bytes_read < effective_content_length)
                            {
                                int bytes_read_this_iteration = effective_content.Read(buffer, 0, buffer.Length);
                                if (bytes_read_this_iteration == 0)
                                {
                                    throw new Exception("Unexpectedly reached the end of the stream before all data was read.");
                                }
                                fs.Write(buffer, 0, bytes_read_this_iteration);
                                bytes_read += bytes_read_this_iteration;
                            }
                        }
                    }
                }
                catch
                {
                    // clean up
                    sql = @"delete from bug_posts where bp_id = $bp";

                    sql = sql.Replace("$bp", Convert.ToString(bp_id));

                    DbUtil.execute_nonquery(sql);

                    throw;
                }

                if (send_notifications)
                {
                    Bug.send_notifications(Bug.UPDATE, bugid, security);
                }
                return(bp_id);
            }
            finally
            {
                // If this procedure "owns" the content (instead of our caller owning it), dispose it.
                if (effective_content != null && effective_content != content)
                {
                    effective_content.Dispose();
                }
            }
        }
Esempio n. 8
0
        public static int copy_user(
            string username,
            string email,
            string firstname,
            string lastname,
            string signature,
            int salt,
            string password,
            string template_username,
            bool use_domain_as_org_name)
        {
            // get all the org columns

            Util.write_to_log("copy_user creating " + username + " from template user " + template_username);
            StringBuilder org_columns = new StringBuilder();

            string sql = "";

            if (use_domain_as_org_name)
            {
                sql = @" /* get org cols */
select sc.name
from syscolumns sc
inner join sysobjects so on sc.id = so.id
where so.name = 'orgs'
and sc.name not in ('og_id', 'og_name', 'og_domain')";

                DataSet ds = DbUtil.get_dataset(sql);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    org_columns.Append(",");
                    org_columns.Append("[");
                    org_columns.Append(Convert.ToString(dr["name"]));
                    org_columns.Append("]");
                }
            }


            sql = @"
/* copy user */
declare @template_user_id int
declare @template_org_id int
select @template_user_id = us_id,
@template_org_id = us_org 
from users where us_username = N'$template_user'

declare @org_id int
set @org_id = -1

IF $use_domain_as_org_name = 1
BEGIN
    select @org_id = og_id from orgs where og_domain = N'$domain'
    IF @org_id = -1
    BEGIN
        insert into orgs
        (
            og_name,
            og_domain       
            $ORG_COLUMNS        
        )
        select 
        N'$domain',
        N'$domain'
        $ORG_COLUMNS
        from orgs where og_id = @template_org_id
        select @org_id = scope_identity()
    END
END

declare @new_user_id int
set @new_user_id = -1

IF NOT EXISTS (SELECT us_id FROM users WHERE us_username = '******')
BEGIN

insert into users
	(us_username, us_email, us_firstname, us_lastname, us_signature, us_salt, us_password,
	us_default_query,
	us_enable_notifications,
	us_auto_subscribe,
	us_auto_subscribe_own_bugs,
	us_auto_subscribe_reported_bugs,
	us_send_notifications_to_self,
	us_active,
	us_bugs_per_page,
	us_forced_project,
	us_reported_notifications,
	us_assigned_notifications,
	us_subscribed_notifications,
	us_use_fckeditor,
	us_enable_bug_list_popups,
	us_org)

select
	N'$username', N'$email', N'$firstname', N'$lastname', N'$signature', $salt, N'$password',
	us_default_query,
	us_enable_notifications,
	us_auto_subscribe,
	us_auto_subscribe_own_bugs,
	us_auto_subscribe_reported_bugs,
	us_send_notifications_to_self,
	1, -- active
	us_bugs_per_page,
	us_forced_project,
	us_reported_notifications,
	us_assigned_notifications,
	us_subscribed_notifications,
	us_use_fckeditor,
	us_enable_bug_list_popups,
	case when @org_id = -1 then us_org else @org_id end
	from users where us_id = @template_user_id

select @new_user_id = scope_identity()

insert into project_user_xref
	(pu_project, pu_user, pu_auto_subscribe, pu_permission_level, pu_admin)

select pu_project, @new_user_id, pu_auto_subscribe, pu_permission_level, pu_admin
	from project_user_xref
	where pu_user = @template_user_id

select @new_user_id

END
";
            sql = sql.Replace("$username", username.Replace("'", "''"));
            sql = sql.Replace("$email", email.Replace("'", "''"));
            sql = sql.Replace("$firstname", firstname.Replace("'", "''"));
            sql = sql.Replace("$lastname", lastname.Replace("'", "''"));
            sql = sql.Replace("$signature", signature.Replace("'", "''"));
            sql = sql.Replace("$salt", Convert.ToString(salt));
            sql = sql.Replace("$password", password);
            sql = sql.Replace("$template_user", template_username.Replace("'", "''"));

            sql = sql.Replace("$use_domain_as_org_name", Convert.ToString(use_domain_as_org_name ? "1" : "0"));

            string[] email_parts = email.Split('@');
            if (email_parts.Length == 2)
            {
                sql = sql.Replace("$domain", email_parts[1].Replace("'", "''"));
            }
            else
            {
                sql = sql.Replace("$domain", email.Replace("'", "''"));
            }

            sql = sql.Replace("$ORG_COLUMNS", org_columns.ToString());
            return(Convert.ToInt32(DbUtil.execute_scalar(sql)));
        }
Esempio n. 9
0
        ///////////////////////////////////////////////////////////////////////
        public void Page_Load(Object sender, EventArgs e)
        {
            Util.set_context(HttpContext.Current);
            Util.do_not_cache(Response);

            if (Util.get_setting("ShowForgotPasswordLink", "0") == "0")
            {
                Response.Write("Sorry, Web.config ShowForgotPasswordLink is set to 0");
                Response.End();
            }

            if (!IsPostBack)
            {
                Page.Header.Title = Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                                    + "forgot password";
            }
            else
            {
                msg.InnerHtml = "";

                if (email.Value == "" && username.Value == "")
                {
                    msg.InnerHtml = "Enter either your Username or your Email address.";
                }
                else if (email.Value != "" && !Util.validate_email(email.Value))
                {
                    msg.InnerHtml = "Format of email address is invalid.";
                }
                else
                {
                    int user_count = 0;
                    int user_id    = 0;

                    if (email.Value != "" && username.Value == "")
                    {
                        // check if email exists
                        SQLString sql = new SQLString("select count(1) from users where us_email = @email");
                        sql.AddParameterWithValue("email", email.Value);
                        user_count = (int)DbUtil.execute_scalar(sql);

                        if (user_count == 1)
                        {
                            sql = new SQLString("select us_id from users where us_email = @email");
                            sql.AddParameterWithValue("email", email.Value);
                            user_id = (int)DbUtil.execute_scalar(sql);
                        }
                    }
                    else if (email.Value == "" && username.Value != "")
                    {
                        // check if email exists
                        SQLString sql = new SQLString(
                            "select count(1) from users where isnull(us_email,'') != '' and  us_username = @username");
                        sql.AddParameterWithValue("username", username.Value);
                        user_count = (int)DbUtil.execute_scalar(sql);

                        if (user_count == 1)
                        {
                            sql = new SQLString("select us_id from users where us_username = @username");
                            sql.AddParameterWithValue("username", username.Value);
                            user_id = (int)DbUtil.execute_scalar(sql);
                        }
                    }
                    else if (email.Value != "" && username.Value != "")
                    {
                        // check if email exists
                        SQLString sql = new SQLString(
                            "select count(1) from users where us_username = @username and us_email = @email");
                        sql.AddParameterWithValue("username", username.Value);
                        sql.AddParameterWithValue("email", email.Value);
                        user_count = (int)DbUtil.execute_scalar(sql);

                        if (user_count == 1)
                        {
                            sql = new SQLString(
                                "select us_id from users where us_username = @username and us_email = @email");
                            sql.AddParameterWithValue("username", username.Value);
                            sql.AddParameterWithValue("email", email.Value);
                            user_id = (int)DbUtil.execute_scalar(sql);
                        }
                    }


                    if (user_count == 1)
                    {
                        string guid = Guid.NewGuid().ToString();
                        var    sql  = new SQLString(@"
declare @username nvarchar(255)
declare @email nvarchar(255)

select @username = us_username, @email = us_email
	from users where us_id = @user_id

insert into emailed_links
	(el_id, el_date, el_email, el_action, el_user_id)
	values (@guid, getdate(), @email, N'forgot', @user_id)

select @username us_username, @email us_email");

                        sql = sql.AddParameterWithValue("guid", guid);
                        sql = sql.AddParameterWithValue("user_id", Convert.ToString(user_id));

                        DataRow dr = DbUtil.get_datarow(sql);

                        string result = Email.send_email(
                            (string)dr["us_email"],
                            Util.get_setting("NotificationEmailFrom", ""),
                            "", // cc
                            "reset password",

                            "Click to <a href='"
                            + Util.get_setting("AbsoluteUrlPrefix", "")
                            + "change_password.aspx?id="
                            + guid
                            + "'>reset password</a> for user \""
                            + (string)dr["us_username"]
                            + "\".",

                            MailFormat.Html);

                        if (result == "")
                        {
                            msg.InnerHtml = "An email with password info has been sent to you.";
                        }
                        else
                        {
                            msg.InnerHtml  = "There was a problem sending the email.";
                            msg.InnerHtml += "<br>" + result;
                        }
                    }
                    else
                    {
                        msg.InnerHtml = "Unknown username or email address.<br>Are you sure you spelled everything correctly?<br>Try just username, just email, or both.";
                    }
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////
        protected void Page_Load(Object sender, EventArgs e)
        {
            Util.do_not_cache(Response);

            this.Master.Menu.SelectedItem = Util.get_setting("PluralBugLabel", "bugs");

            if (User.IsInRole(BtnetRoles.Admin) || User.Identity.GetCanEditAndDeleteBugs())
            {
                //
            }
            else
            {
                Response.Write("You are not allowed to use this page.");
                Response.End();
            }

            string attachment_id_string = Util.sanitize_integer(Request["id"]);
            string bug_id_string        = Util.sanitize_integer(Request["bug_id"]);

            int permission_level = Bug.get_bug_permission_level(Convert.ToInt32(bug_id_string), User.Identity);

            if (permission_level != PermissionLevel.All)
            {
                Response.Write("You are not allowed to edit this item");
                Response.End();
            }


            if (IsPostBack)
            {
                // save the filename before deleting the row
                sql = new SQLString(@"select bp_file from bug_posts where bp_id = @ba");
                sql = sql.AddParameterWithValue("ba", attachment_id_string);
                string filename = (string)DbUtil.execute_scalar(sql);

                // delete the row representing the attachment
                sql = new SQLString(@"delete bug_post_attachments where bpa_post = @ba
            delete bug_posts where bp_id = @ba");
                sql = sql.AddParameterWithValue("ba", attachment_id_string);
                DbUtil.execute_nonquery(sql);

                // delete the file too
                string upload_folder = Util.get_upload_folder();
                if (upload_folder != null)
                {
                    StringBuilder path = new StringBuilder(upload_folder);
                    path.Append("\\");
                    path.Append(bug_id_string);
                    path.Append("_");
                    path.Append(attachment_id_string);
                    path.Append("_");
                    path.Append(filename);
                    if (System.IO.File.Exists(path.ToString()))
                    {
                        System.IO.File.Delete(path.ToString());
                    }
                }


                Response.Redirect("edit_bug.aspx?id=" + bug_id_string);
            }
            else
            {
                Page.Header.Title = Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                                    + "delete attachment";

                back_href.HRef = "edit_bug.aspx?id=" + bug_id_string;

                sql = new SQLString(@"select bp_file from bug_posts where bp_id = @id");
                sql = sql.AddParameterWithValue("id", attachment_id_string);

                DataRow dr = DbUtil.get_datarow(sql);

                string s = Convert.ToString(dr["bp_file"]);

                confirm_href.InnerText = "confirm delete of attachment: " + s;

                row_id.Value = attachment_id_string;
            }
        }
Esempio n. 11
0
		///////////////////////////////////////////////////////////////////////
		public static void print_bug (HttpResponse Response, DataRow dr, Security security, 
            bool include_style, 
            bool images_inline, 
            bool history_inline,
            bool internal_posts)
		{

			int bugid = Convert.ToInt32(dr["id"]);
			string string_bugid = Convert.ToString(bugid);

            if (include_style) // when sending emails
            {
                Response.Write("\n<style>\n");

                // If this file exists, use it.

                string map_path = (string) HttpRuntime.Cache["MapPath"];

                string css_for_email_file = map_path + "\\custom\\btnet_css_for_email.css";

                try
                {
                    if (System.IO.File.Exists(css_for_email_file))
                    {
                        Response.WriteFile(css_for_email_file);
					    Response.Write("\n");
                    }
                    else
                    {
                        css_for_email_file = map_path + "\\Content\\bootstrap.min.css";
                        Response.WriteFile(css_for_email_file);
					    Response.Write("\n");
                        //css_for_email_file = map_path + "\\custom\\" + "btnet_custom.css";
                        //if (System.IO.File.Exists(css_for_email_file))
                        //{
                        //    Response.WriteFile(css_for_email_file);
                        //    Response.Write("\n");
                        //}
                    }
                }
                catch (Exception e)
                {
                    Util.write_to_log("Exception trying to read css file for email \"" 
                        + css_for_email_file
                        + "\":" 
                        + e.Message);
                }

                // underline links in the emails to make them more obvious
                Response.Write("\na {text-decoration: underline; }");
                Response.Write("\na:visited {text-decoration: underline; }");
                Response.Write("\na:hover {text-decoration: underline; }");
                Response.Write("\n</style>\n");
            }

			Response.Write ("<body style='background:white'>");
			Response.Write ("<b>"
				+ Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug"))
				+ " ID:&nbsp;<a href="
				+ Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
				+ "edit_bug.aspx?id="
				+ string_bugid
				+ ">"
				+ string_bugid
				+ "</a>");

            if (Util.get_setting("EnableMobile", "0") == "1")
            {
                Response.Write(
                    "&nbsp;&nbsp;&nbsp;&nbsp;Mobile link:&nbsp;<a href="
                    + Util.get_setting("AbsoluteUrlPrefix", "http://127.0.0.1/")
                    + "mbug.aspx?id="
                    + string_bugid
                    + ">"
                    + Util.get_setting("AbsoluteUrlPrefix", "http://127.0.0.1/")
                    + "mbug.aspx?id="
                    + string_bugid
                    + "</a>");

            }

            Response.Write("<br>");

			Response.Write ("Short desc:&nbsp;<a href="
				+ Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
				+ "edit_bug.aspx?id="
				+ string_bugid
				+ ">"
				+ HttpUtility.HtmlEncode((string)dr["short_desc"])
				+ "</a></b><p>");

			// start of the table with the bug fields
			Response.Write ("\n<table class='table'>");
            Response.Write("\n<tr><td>Last changed by<td>"
				+ format_username((string)dr["last_updated_user"],(string)dr["last_updated_fullname"])
				+ "&nbsp;");
            Response.Write("\n<tr><td>Reported By<td>"
				+ format_username((string)dr["reporter"],(string)dr["reporter_fullname"])
				+ "&nbsp;");
            Response.Write("\n<tr><td>Reported On<td>" + Util.format_db_date_and_time(dr["reported_date"]) + "&nbsp;");

            if (security.user.tags_field_permission_level > 0)
	            Response.Write("\n<tr><td>Tags<td>" + dr["bg_tags"] + "&nbsp;");

            if (security.user.project_field_permission_level > 0)
	            Response.Write("\n<tr><td>Project<td>" + dr["current_project"] + "&nbsp;");

            if (security.user.org_field_permission_level > 0)
	            Response.Write("\n<tr><td>Organization<td>" + dr["og_name"] + "&nbsp;");

            if (security.user.category_field_permission_level > 0)
	            Response.Write("\n<tr><td>Category<td>" + dr["category_name"] + "&nbsp;");

            if (security.user.priority_field_permission_level > 0)
	            Response.Write("\n<tr><td>Priority<td>" + dr["priority_name"] + "&nbsp;");

            if (security.user.assigned_to_field_permission_level > 0)
	            Response.Write("\n<tr><td>Assigned<td>"
					+ format_username((string)dr["assigned_to_username"],(string)dr["assigned_to_fullname"])
					+ "&nbsp;");

            if (security.user.status_field_permission_level > 0)
            	Response.Write("\n<tr><td>Status<td>" + dr["status_name"] + "&nbsp;");

			if (security.user.udf_field_permission_level > 0)
				if (Util.get_setting("ShowUserDefinedBugAttribute","1") == "1")
				{
					Response.Write("\n<tr><td>"
						+ Util.get_setting("UserDefinedBugAttributeName","YOUR ATTRIBUTE")
						+ "<td>"
						+ dr["udf_name"] + "&nbsp;");
				}

			// Get custom column info  (There's an inefficiency here - we just did this
			// same call in get_bug_datarow...)

			
			DataSet ds_custom_cols = Util.get_custom_columns();


			// Show custom columns

			foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
			{
                string column_name = (string) drcc["name"];

                if (security.user.dict_custom_field_permission_level[column_name] == Security.PERMISSION_NONE)
                {
                    continue;
                }

                Response.Write("\n<tr><td>");
				Response.Write (column_name);
				Response.Write ("<td>");

				if ((string)drcc["datatype"] == "datetime")
				{
					object dt = dr[(string)drcc["name"]];

					Response.Write (Util.format_db_date_and_time(dt));
				}
				else
				{
					string s = "";

					if ((string)drcc["dropdown type"] == "users")
					{
						object obj = dr[(string)drcc["name"]];
						if (obj.GetType() != typeof(System.DBNull))
						{
							int userid = Convert.ToInt32(obj);
							if (userid != 0)
							{
								string sql_get_username = "******";
								s = (string) DbUtil.execute_scalar(sql_get_username.Replace("$1", Convert.ToString(userid)));
							}
						}
					}
					else
					{
						s = Convert.ToString(dr[(string)drcc["name"]]);
					}

					s = HttpUtility.HtmlEncode(s);
					s = s.Replace("\n","<br>");
					s = s.Replace("  ","&nbsp; ");
					s = s.Replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;");
					Response.Write (s);
				}
				Response.Write ("&nbsp;");
			}


			// create project custom dropdowns
			if ((int)dr["project"] != 0)
			{

				string sql = @"select
					isnull(pj_enable_custom_dropdown1,0) [pj_enable_custom_dropdown1],
					isnull(pj_enable_custom_dropdown2,0) [pj_enable_custom_dropdown2],
					isnull(pj_enable_custom_dropdown3,0) [pj_enable_custom_dropdown3],
					isnull(pj_custom_dropdown_label1,'') [pj_custom_dropdown_label1],
					isnull(pj_custom_dropdown_label2,'') [pj_custom_dropdown_label2],
					isnull(pj_custom_dropdown_label3,'') [pj_custom_dropdown_label3]
					from projects where pj_id = $pj";

				sql = sql.Replace("$pj", Convert.ToString((int)dr["project"]));

				DataRow project_dr = DbUtil.get_datarow(sql);


				if (project_dr != null)
				{
					for (int i = 1; i < 4; i++)
					{
						if ((int)project_dr["pj_enable_custom_dropdown" + Convert.ToString(i)] == 1)
						{
                            Response.Write("\n<tr><td>");
							Response.Write (project_dr["pj_custom_dropdown_label" + Convert.ToString(i)]);
							Response.Write ("<td>");
							Response.Write (dr["bg_project_custom_dropdown_value"  + Convert.ToString(i)]);
							Response.Write ("&nbsp;");
						}
					}
				}
			}



			Response.Write("\n</table><p>"); // end of the table with the bug fields

			// Relationships
			if (Util.get_setting("EnableRelationships", "0") == "1")
			{
				write_relationships(Response, bugid);
			}

			// Tasks
			if (Util.get_setting("EnableTasks", "0") == "1")
			{
				write_tasks(Response, bugid);
			}


            DataSet ds_posts = get_bug_posts(bugid, security.user.external_user, history_inline);
			write_posts (
                ds_posts,
                Response, 
                bugid, 
                0, 
                false, /* don't write links */
                images_inline, 
                history_inline, 
                internal_posts,
                security.user);

			Response.Write ("</body>");

		}