From 556de0d4ac56f5eeb1fe163d5b2b9d6703bdebe2 Mon Sep 17 00:00:00 2001 From: Eggbertx Date: Sun, 6 Apr 2025 16:07:37 -0700 Subject: [PATCH] Show secure tripcodes --- .../internal/pre2021/posts.go | 6 +++--- .../internal/pre2021/queries.go | 2 +- pkg/building/catalog.go | 6 +++--- pkg/building/posts.go | 20 +++++++++---------- pkg/gcsql/posts.go | 16 +++++++-------- pkg/gcsql/posts_test.go | 17 ++++++++-------- pkg/gcsql/setup_test.go | 6 +++--- pkg/gcsql/threads.go | 4 ++-- pkg/posting/post.go | 2 +- pkg/posting/post_test.go | 2 +- templates/manage_recentposts.html | 2 +- templates/post.html | 2 +- templates/post_edit.html | 2 +- 13 files changed, 44 insertions(+), 43 deletions(-) diff --git a/cmd/gochan-migration/internal/pre2021/posts.go b/cmd/gochan-migration/internal/pre2021/posts.go index 6459dd0e..58fdadc9 100644 --- a/cmd/gochan-migration/internal/pre2021/posts.go +++ b/cmd/gochan-migration/internal/pre2021/posts.go @@ -97,8 +97,8 @@ func (m *Pre2021Migrator) MigratePosts() error { for rows.Next() { var thread migrationPost if err = rows.Scan( - &thread.oldID, &thread.oldBoardID, &thread.oldParentID, &thread.Name, &thread.Tripcode, &thread.IsSecureTripcode, - &thread.Email, &thread.Subject, &thread.Message, &thread.MessageRaw, &thread.Password, &thread.filename, + &thread.oldID, &thread.oldBoardID, &thread.oldParentID, &thread.Name, &thread.Tripcode, &thread.Email, + &thread.Subject, &thread.Message, &thread.MessageRaw, &thread.Password, &thread.filename, &thread.filenameOriginal, &thread.fileChecksum, &thread.filesize, &thread.imageW, &thread.imageH, &thread.thumbW, &thread.thumbH, &thread.IP, &thread.CreatedOn, &thread.autosage, &thread.bumped, &thread.stickied, &thread.locked, @@ -137,7 +137,7 @@ func (m *Pre2021Migrator) MigratePosts() error { for replyRows.Next() { var reply migrationPost if err = replyRows.Scan( - &reply.oldID, &reply.oldBoardID, &reply.oldParentID, &reply.Name, &reply.Tripcode, &reply.IsSecureTripcode, + &reply.oldID, &reply.oldBoardID, &reply.oldParentID, &reply.Name, &reply.Tripcode, &reply.Email, &reply.Subject, &reply.Message, &reply.MessageRaw, &reply.Password, &reply.filename, &reply.filenameOriginal, &reply.fileChecksum, &reply.filesize, &reply.imageW, &reply.imageH, &reply.thumbW, &reply.thumbH, &reply.IP, &reply.CreatedOn, &reply.autosage, diff --git a/cmd/gochan-migration/internal/pre2021/queries.go b/cmd/gochan-migration/internal/pre2021/queries.go index 6ee2136a..8456dad7 100644 --- a/cmd/gochan-migration/internal/pre2021/queries.go +++ b/cmd/gochan-migration/internal/pre2021/queries.go @@ -8,7 +8,7 @@ default_style, locked, created_on, anonymous, forced_anon, autosage_after, no_im redirect_to_thread, require_file, enable_catalog FROM DBPREFIXboards` - postsQuery = `SELECT id, boardid, parentid, name, tripcode, is_secure_tripcode, email, subject, message, message_raw, password, filename, + postsQuery = `SELECT id, boardid, parentid, name, tripcode, email, subject, message, message_raw, password, filename, filename_original, file_checksum, filesize, image_w, image_h, thumb_w, thumb_h, ip, timestamp, autosage, bumped, stickied, locked FROM DBPREFIXposts WHERE deleted_timestamp IS NULL` diff --git a/pkg/building/catalog.go b/pkg/building/catalog.go index 0495d87f..952fa844 100644 --- a/pkg/building/catalog.go +++ b/pkg/building/catalog.go @@ -63,9 +63,9 @@ func (catalog *boardCatalog) fillPages(threadsPerPage int, threads []catalogThre } func getBoardTopPosts(board string) ([]*Post, error) { - const query = `SELECT id, thread_id, ip, name, tripcode, email, subject, created_on, last_modified, parent_id, - last_bump, message, message_raw, board_id, dir, original_filename, filename, checksum, filesize, tw, th, - width, height, locked, stickied, cyclical, flag, country, is_deleted + const query = `SELECT id, thread_id, ip, name, tripcode, is_secure_tripcode, email, subject, created_on, + last_modified, parent_id, last_bump, message, message_raw, board_id, dir, original_filename, filename, + checksum, filesize, tw, th, width, height, locked, stickied, cyclical, flag, country, is_deleted FROM DBPREFIXv_building_posts WHERE id = parent_id AND dir = ?` var posts []*Post diff --git a/pkg/building/posts.go b/pkg/building/posts.go index b01ac1e3..3b040461 100644 --- a/pkg/building/posts.go +++ b/pkg/building/posts.go @@ -196,7 +196,7 @@ func QueryPosts(query string, params []any, cb func(*Post) error) error { } var lastBump time.Time dest = append(dest, - &post.Name, &post.Tripcode, &post.Email, &post.Subject, &post.CreatedOn, + &post.Name, &post.Tripcode, &post.IsSecureTripcode, &post.Email, &post.Subject, &post.CreatedOn, &post.LastModified, &post.ParentID, &lastBump, &post.Message, &post.MessageRaw, &post.BoardID, &post.BoardDir, &post.OriginalFilename, &post.Filename, &post.Checksum, &post.Filesize, &post.ThumbnailWidth, &post.ThumbnailHeight, &post.UploadWidth, &post.UploadHeight, @@ -224,9 +224,9 @@ func QueryPosts(query string, params []any, cb func(*Post) error) error { } func GetBuildablePostsByIP(ip string, limit int) ([]*Post, error) { - query := `SELECT id, thread_id, ip, name, tripcode, email, subject, created_on, last_modified, parent_id, - last_bump, message, message_raw, board_id, dir, original_filename, filename, checksum, filesize, tw, th, - width, height, locked, stickied, cyclical, flag, country, is_deleted + query := `SELECT id, thread_id, ip, name, tripcode, is_secure_tripcode, email, subject, created_on, last_modified, + parent_id, last_bump, message, message_raw, board_id, dir, original_filename, filename, checksum, filesize, + tw, th, width, height, locked, stickied, cyclical, flag, country, is_deleted FROM DBPREFIXv_building_posts WHERE ip = PARAM_ATON ORDER BY id DESC` if limit > 0 { query += " LIMIT " + strconv.Itoa(limit) @@ -241,9 +241,9 @@ func GetBuildablePostsByIP(ip string, limit int) ([]*Post, error) { } func getThreadPosts(thread *gcsql.Thread) ([]*Post, error) { - const query = `SELECT id, thread_id, ip, name, tripcode, email, subject, created_on, last_modified, parent_id, - last_bump, message, message_raw, board_id, dir, original_filename, filename, checksum, filesize, tw, th, - width, height, locked, stickied, cyclical, flag, country, is_deleted + const query = `SELECT id, thread_id, ip, name, tripcode, is_secure_tripcode, email, subject, created_on, + last_modified, parent_id, last_bump, message, message_raw, board_id, dir, original_filename, filename, + checksum, filesize, tw, th, width, height, locked, stickied, cyclical, flag, country, is_deleted FROM DBPREFIXv_building_posts WHERE thread_id = ? ORDER BY id ASC` var posts []*Post err := QueryPosts(query, []any{thread.ID}, func(p *Post) error { @@ -254,9 +254,9 @@ func getThreadPosts(thread *gcsql.Thread) ([]*Post, error) { } func GetRecentPosts(boardid int, limit int) ([]*Post, error) { - query := `SELECT id, thread_id, ip, name, tripcode, email, subject, created_on, last_modified, parent_id, - last_bump, message, message_raw, board_id, dir, original_filename, filename, checksum, filesize, tw, th, - width, height, locked, stickied, cyclical, flag, country, is_deleted + query := `SELECT id, thread_id, ip, name, tripcode, is_secure_tripcode, email, subject, created_on, last_modified, + parent_id, last_bump, message, message_raw, board_id, dir, original_filename, filename, checksum, filesize, + tw, th, width, height, locked, stickied, cyclical, flag, country, is_deleted FROM DBPREFIXv_building_posts` var args []any diff --git a/pkg/gcsql/posts.go b/pkg/gcsql/posts.go index bcd73bc5..d191ea36 100644 --- a/pkg/gcsql/posts.go +++ b/pkg/gcsql/posts.go @@ -18,8 +18,8 @@ const ( SELECT thread_id FROM DBPREFIXposts WHERE id = ?))` selectPostsBaseSQL = `SELECT - id, thread_id, is_top_post, IP_NTOA, created_on, name, tripcode, is_role_signature, - email, subject, message, message_raw, password, deleted_at, is_deleted, + id, thread_id, is_top_post, IP_NTOA, created_on, name, tripcode, is_secure_tripcode, + is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, COALESCE(banned_message,'') AS banned_message, flag, country FROM DBPREFIXposts ` ) @@ -42,9 +42,9 @@ func GetPostFromID(id int, onlyNotDeleted bool, requestOptions ...*RequestOption opts := setupOptions(requestOptions...) err := QueryRow(opts, query, []any{id}, []any{ &post.ID, &post.ThreadID, &post.IsTopPost, &post.IP, &post.CreatedOn, &post.Name, - &post.Tripcode, &post.IsRoleSignature, &post.Email, &post.Subject, &post.Message, - &post.MessageRaw, &post.Password, &post.DeletedAt, &post.IsDeleted, - &post.BannedMessage, &post.Flag, &post.Country, + &post.Tripcode, &post.IsSecureTripcode, &post.IsRoleSignature, &post.Email, + &post.Subject, &post.Message, &post.MessageRaw, &post.Password, &post.DeletedAt, + &post.IsDeleted, &post.BannedMessage, &post.Flag, &post.Country, }) if errors.Is(err, sql.ErrNoRows) { return nil, ErrPostDoesNotExist @@ -412,9 +412,9 @@ func (p *Post) Insert(bumpThread bool, boardID int, locked bool, stickied bool, return ErrorPostAlreadySent } insertSQL := `INSERT INTO DBPREFIXposts - (thread_id, is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, + (thread_id, is_top_post, ip, created_on, name, tripcode, is_secure_tripcode, is_role_signature, email, subject, message, message_raw, password, flag, country) - VALUES(?,?,PARAM_ATON,CURRENT_TIMESTAMP,?,?,?,?,?,?,?,?,?,?)` + VALUES(?,?,PARAM_ATON,CURRENT_TIMESTAMP,?,?,?,?,?,?,?,?,?,?,?)` bumpSQL := `UPDATE DBPREFIXthreads SET last_bump = CURRENT_TIMESTAMP WHERE id = ?` if p.ThreadID == 0 { @@ -438,7 +438,7 @@ func (p *Post) Insert(bumpThread bool, boardID int, locked bool, stickied bool, } if _, err = Exec(opts, insertSQL, - p.ThreadID, p.IsTopPost, p.IP, p.Name, p.Tripcode, p.IsRoleSignature, p.Email, p.Subject, + p.ThreadID, p.IsTopPost, p.IP, p.Name, p.Tripcode, p.IsSecureTripcode, p.IsRoleSignature, p.Email, p.Subject, p.Message, p.MessageRaw, p.Password, p.Flag, p.Country, ); err != nil { return err diff --git a/pkg/gcsql/posts_test.go b/pkg/gcsql/posts_test.go index 82fdf8e3..162cb8ae 100644 --- a/pkg/gcsql/posts_test.go +++ b/pkg/gcsql/posts_test.go @@ -2,6 +2,7 @@ package gcsql import ( "testing" + "time" "github.com/DATA-DOG/go-sqlmock" "github.com/gochan-org/gochan/pkg/config" @@ -15,14 +16,13 @@ var ( insertIntoThreadsPostgres = insertIntoThreadsBase + `\(\$1,\$2,\$3,\$4,\$5\)` insertIntoPostsBase = `INSERT INTO posts\s*` + - `\(thread_id, is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject,\s+` + + `\(thread_id, is_top_post, ip, created_on, name, tripcode, is_secure_tripcode, is_role_signature, email, subject,\s+` + `message, message_raw, password, flag, country\)\s+VALUES` - insertIntoPostsMySQL = insertIntoPostsBase + `\(\?,\?,INET6_ATON\(\?\),CURRENT_TIMESTAMP,\?,\?,\?,\?,\?,\?,\?,\?,\?,\?\)` - insertIntoPostsPostgres = insertIntoPostsBase + `\(\$1,\$2,\$3,CURRENT_TIMESTAMP,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$11,\$12,\$13\)` + insertIntoPostsMySQL = insertIntoPostsBase + `\(\?,\?,INET6_ATON\(\?\),CURRENT_TIMESTAMP,\?,\?,\?,\?,\?,\?,\?,\?,\?,\?,\?\)` + insertIntoPostsPostgres = insertIntoPostsBase + `\(\$1,\$2,\$3,CURRENT_TIMESTAMP,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$11,\$12,\$13,\$14\)` ) func setupPostTest(t *testing.T, driver string) sqlmock.Sqlmock { - t.Helper() _, err := testutil.GoToGochanRoot(t) if !assert.NoError(t, err) { t.FailNow() @@ -84,16 +84,17 @@ func createThreadTestRun(t *testing.T, driver string) { if !assert.NoError(t, err) { t.FailNow() } - p := Post{ThreadID: threadID, Message: "test", IP: "192.168.56.1", IsTopPost: true} + p := Post{ThreadID: threadID, Message: "test", MessageRaw: "test", IP: "192.168.56.1", IsTopPost: true, CreatedOn: time.Now()} if driver == "mysql" { query = insertIntoPostsMySQL } else { query = insertIntoPostsPostgres } - mock.ExpectPrepare(query). - ExpectExec().WithArgs(p.ThreadID, p.IsTopPost, p.IP, "", p.Name, false, "", "", "test", "", - "", "", "").WillReturnResult(sqlmock.NewResult(1, 1)) + mock.ExpectPrepare(query).ExpectExec(). + WithArgs(p.ThreadID, p.IsTopPost, p.IP, p.Name, p.Tripcode, p.IsSecureTripcode, p.IsRoleSignature, p.Email, + p.Subject, p.Message, p.MessageRaw, p.Password, p.Flag, p.Country). + WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectPrepare(`SELECT MAX\(id\) FROM posts`).ExpectQuery().WithoutArgs(). WillReturnRows(mock.NewRows([]string{"MAX(id)"}).AddRow(1)) if driver == "mysql" { diff --git a/pkg/gcsql/setup_test.go b/pkg/gcsql/setup_test.go index 9bef7237..d65a5f10 100644 --- a/pkg/gcsql/setup_test.go +++ b/pkg/gcsql/setup_test.go @@ -17,7 +17,7 @@ var ( `CREATE TABLE boards\(\s*id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,\s+section_id BIGINT NOT NULL,\s+uri VARCHAR\(45\) NOT NULL,\s+dir VARCHAR\(45\) NOT NULL,\s+navbar_position SMALLINT NOT NULL,\s+title VARCHAR\(45\) NOT NULL,\s+subtitle VARCHAR\(64\) NOT NULL,\s+description VARCHAR\(64\) NOT NULL,\s+max_file_size INT NOT NULL,\s+max_threads SMALLINT NOT NULL, default_style VARCHAR\(45\) NOT NULL,\s+locked BOOL NOT NULL,\s+created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+anonymous_name VARCHAR\(45\) NOT NULL DEFAULT 'Anonymous',\s+force_anonymous BOOL NOT NULL,\s+autosage_after SMALLINT NOT NULL,\s+no_images_after SMALLINT NOT NULL,\s+max_message_length SMALLINT NOT NULL,\s+min_message_length SMALLINT NOT NULL,\s+allow_embeds BOOL NOT NULL,\s+redirect_to_thread BOOL NOT NULL,\s+require_file BOOL NOT NULL,\s+enable_catalog BOOL NOT NULL,\s+CONSTRAINT boards_section_id_fk\s+FOREIGN KEY\(section_id\) REFERENCES sections\(id\),\s+CONSTRAINT boards_dir_unique UNIQUE\(dir\),\s+CONSTRAINT boards_uri_unique UNIQUE\(uri\)\s*\)`, `CREATE TABLE threads\(\s*id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,\s+board_id BIGINT NOT NULL,\s+locked BOOL NOT NULL DEFAULT FALSE,\s+stickied BOOL NOT NULL DEFAULT FALSE,\s+anchored BOOL NOT NULL DEFAULT FALSE,\s+cyclical BOOL NOT NULL DEFAULT FALSE,\s+last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+CONSTRAINT threads_board_id_fk\s+FOREIGN KEY\(board_id\) REFERENCES boards\(id\) ON DELETE CASCADE\s*\)`, `CREATE INDEX thread_deleted_index ON threads\(is_deleted\)`, - `CREATE TABLE posts\(\s+id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,\s+thread_id BIGINT NOT NULL,\s+is_top_post BOOL NOT NULL DEFAULT FALSE,\s+ip VARBINARY\(16\) NOT NULL,\s+created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+name VARCHAR\(50\) NOT NULL DEFAULT '',\s+tripcode VARCHAR\(10\) NOT NULL DEFAULT '',\s+is_role_signature BOOL NOT NULL DEFAULT FALSE, email VARCHAR\(50\) NOT NULL DEFAULT '',\s+subject VARCHAR\(100\) NOT NULL DEFAULT '',\s+message TEXT NOT NULL,\s+message_raw TEXT NOT NULL,\s+password TEXT NOT NULL,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+banned_message TEXT,\s+flag VARCHAR\(45\) NOT NULL DEFAULT '',\s+country VARCHAR\(80\) NOT NULL DEFAULT '',\s+CONSTRAINT posts_thread_id_fk\s+FOREIGN KEY\(thread_id\) REFERENCES threads\(id\) ON DELETE CASCADE \)`, + `CREATE TABLE posts\(\s+id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,\s+thread_id BIGINT NOT NULL,\s+is_top_post BOOL NOT NULL DEFAULT FALSE,\s+ip VARBINARY\(16\) NOT NULL,\s+created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+name VARCHAR\(50\) NOT NULL DEFAULT '',\s+tripcode VARCHAR\(10\) NOT NULL DEFAULT '',\s+is_secure_tripcode BOOL NOT NULL DEFAULT FALSE,\s+is_role_signature BOOL NOT NULL DEFAULT FALSE, email VARCHAR\(50\) NOT NULL DEFAULT '',\s+subject VARCHAR\(100\) NOT NULL DEFAULT '',\s+message TEXT NOT NULL,\s+message_raw TEXT NOT NULL,\s+password TEXT NOT NULL,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+banned_message TEXT,\s+flag VARCHAR\(45\) NOT NULL DEFAULT '',\s+country VARCHAR\(80\) NOT NULL DEFAULT '',\s+CONSTRAINT posts_thread_id_fk\s+FOREIGN KEY\(thread_id\) REFERENCES threads\(id\) ON DELETE CASCADE \)`, `CREATE INDEX top_post_index ON posts\(is_top_post\)`, `CREATE TABLE files\(\s+id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,\s+post_id BIGINT NOT NULL,\s+file_order INT NOT NULL,\s+original_filename VARCHAR\(255\) NOT NULL,\s+filename VARCHAR\(45\) NOT NULL,\s+checksum TEXT NOT NULL,\s+file_size INT NOT NULL,\s+is_spoilered BOOL NOT NULL,\s+thumbnail_width INT NOT NULL,\s+thumbnail_height INT NOT NULL,\s+width INT NOT NULL,\s+height INT NOT NULL,\s+CONSTRAINT files_post_id_fk\s+FOREIGN KEY\(post_id\) REFERENCES posts\(id\) ON DELETE CASCADE,\s+CONSTRAINT files_post_id_file_order_unique UNIQUE\(post_id, file_order\) \)`, `CREATE TABLE staff\(\s+id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,\s+username VARCHAR\(45\) NOT NULL,\s+password_checksum VARCHAR\(120\) NOT NULL,\s+global_rank INT,\s+added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_active BOOL NOT NULL DEFAULT TRUE,\s+CONSTRAINT staff_username_unique UNIQUE\(username\) \)`, @@ -42,7 +42,7 @@ var ( `CREATE TABLE boards\(\s*id BIGSERIAL PRIMARY KEY,\s+section_id BIGINT NOT NULL,\s+uri VARCHAR\(45\) NOT NULL,\s+dir VARCHAR\(45\) NOT NULL,\s+navbar_position SMALLINT NOT NULL,\s+title VARCHAR\(45\) NOT NULL,\s+subtitle VARCHAR\(64\) NOT NULL,\s+description VARCHAR\(64\) NOT NULL,\s+max_file_size INT NOT NULL,\s+max_threads SMALLINT NOT NULL, default_style VARCHAR\(45\) NOT NULL,\s+locked BOOL NOT NULL,\s+created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+anonymous_name VARCHAR\(45\) NOT NULL DEFAULT 'Anonymous',\s+force_anonymous BOOL NOT NULL,\s+autosage_after SMALLINT NOT NULL,\s+no_images_after SMALLINT NOT NULL,\s+max_message_length SMALLINT NOT NULL,\s+min_message_length SMALLINT NOT NULL,\s+allow_embeds BOOL NOT NULL,\s+redirect_to_thread BOOL NOT NULL,\s+require_file BOOL NOT NULL,\s+enable_catalog BOOL NOT NULL,\s+CONSTRAINT boards_section_id_fk\s+FOREIGN KEY\(section_id\) REFERENCES sections\(id\),\s+CONSTRAINT boards_dir_unique UNIQUE\(dir\),\s+CONSTRAINT boards_uri_unique UNIQUE\(uri\)\s*\)`, `CREATE TABLE threads\(\s*id BIGSERIAL PRIMARY KEY,\s+board_id BIGINT NOT NULL,\s+locked BOOL NOT NULL DEFAULT FALSE,\s+stickied BOOL NOT NULL DEFAULT FALSE,\s+anchored BOOL NOT NULL DEFAULT FALSE,\s+cyclical BOOL NOT NULL DEFAULT FALSE,\s+last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+CONSTRAINT threads_board_id_fk\s+FOREIGN KEY\(board_id\) REFERENCES boards\(id\) ON DELETE CASCADE\s*\)`, `CREATE INDEX thread_deleted_index ON threads\(is_deleted\)`, - `CREATE TABLE posts\(\s+id BIGSERIAL PRIMARY KEY,\s+thread_id BIGINT NOT NULL,\s+is_top_post BOOL NOT NULL DEFAULT FALSE,\s+ip INET NOT NULL,\s+created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+name VARCHAR\(50\) NOT NULL DEFAULT '',\s+tripcode VARCHAR\(10\) NOT NULL DEFAULT '',\s+is_role_signature BOOL NOT NULL DEFAULT FALSE, email VARCHAR\(50\) NOT NULL DEFAULT '',\s+subject VARCHAR\(100\) NOT NULL DEFAULT '',\s+message TEXT NOT NULL,\s+message_raw TEXT NOT NULL,\s+password TEXT NOT NULL,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+banned_message TEXT,\s+flag VARCHAR\(45\) NOT NULL DEFAULT '',\s+country VARCHAR\(80\) NOT NULL DEFAULT '',\s+CONSTRAINT posts_thread_id_fk\s+FOREIGN KEY\(thread_id\) REFERENCES threads\(id\) ON DELETE CASCADE \)`, + `CREATE TABLE posts\(\s+id BIGSERIAL PRIMARY KEY,\s+thread_id BIGINT NOT NULL,\s+is_top_post BOOL NOT NULL DEFAULT FALSE,\s+ip INET NOT NULL,\s+created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+name VARCHAR\(50\) NOT NULL DEFAULT '',\s+tripcode VARCHAR\(10\) NOT NULL DEFAULT '',\s+is_secure_tripcode BOOL NOT NULL DEFAULT FALSE,\s+is_role_signature BOOL NOT NULL DEFAULT FALSE, email VARCHAR\(50\) NOT NULL DEFAULT '',\s+subject VARCHAR\(100\) NOT NULL DEFAULT '',\s+message TEXT NOT NULL,\s+message_raw TEXT NOT NULL,\s+password TEXT NOT NULL,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+banned_message TEXT,\s+flag VARCHAR\(45\) NOT NULL DEFAULT '',\s+country VARCHAR\(80\) NOT NULL DEFAULT '',\s+CONSTRAINT posts_thread_id_fk\s+FOREIGN KEY\(thread_id\) REFERENCES threads\(id\) ON DELETE CASCADE \)`, `CREATE INDEX top_post_index ON posts\(is_top_post\)`, `CREATE TABLE files\(\s+id BIGSERIAL PRIMARY KEY,\s+post_id BIGINT NOT NULL,\s+file_order INT NOT NULL,\s+original_filename VARCHAR\(255\) NOT NULL,\s+filename VARCHAR\(45\) NOT NULL,\s+checksum TEXT NOT NULL,\s+file_size INT NOT NULL,\s+is_spoilered BOOL NOT NULL,\s+thumbnail_width INT NOT NULL,\s+thumbnail_height INT NOT NULL,\s+width INT NOT NULL,\s+height INT NOT NULL,\s+CONSTRAINT files_post_id_fk\s+FOREIGN KEY\(post_id\) REFERENCES posts\(id\) ON DELETE CASCADE,\s+CONSTRAINT files_post_id_file_order_unique UNIQUE\(post_id, file_order\) \)`, `CREATE TABLE staff\(\s+id BIGSERIAL PRIMARY KEY,\s+username VARCHAR\(45\) NOT NULL,\s+password_checksum VARCHAR\(120\) NOT NULL,\s+global_rank INT,\s+added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_active BOOL NOT NULL DEFAULT TRUE,\s+CONSTRAINT staff_username_unique UNIQUE\(username\) \)`, @@ -67,7 +67,7 @@ var ( `CREATE TABLE boards\(\s*id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\s+section_id BIGINT NOT NULL,\s+uri VARCHAR\(45\) NOT NULL,\s+dir VARCHAR\(45\) NOT NULL,\s+navbar_position SMALLINT NOT NULL,\s+title VARCHAR\(45\) NOT NULL,\s+subtitle VARCHAR\(64\) NOT NULL,\s+description VARCHAR\(64\) NOT NULL,\s+max_file_size INT NOT NULL,\s+max_threads SMALLINT NOT NULL, default_style VARCHAR\(45\) NOT NULL,\s+locked BOOL NOT NULL,\s+created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+anonymous_name VARCHAR\(45\) NOT NULL DEFAULT 'Anonymous',\s+force_anonymous BOOL NOT NULL,\s+autosage_after SMALLINT NOT NULL,\s+no_images_after SMALLINT NOT NULL,\s+max_message_length SMALLINT NOT NULL,\s+min_message_length SMALLINT NOT NULL,\s+allow_embeds BOOL NOT NULL,\s+redirect_to_thread BOOL NOT NULL,\s+require_file BOOL NOT NULL,\s+enable_catalog BOOL NOT NULL,\s+CONSTRAINT boards_section_id_fk\s+FOREIGN KEY\(section_id\) REFERENCES sections\(id\),\s+CONSTRAINT boards_dir_unique UNIQUE\(dir\),\s+CONSTRAINT boards_uri_unique UNIQUE\(uri\)\s*\)`, `CREATE TABLE threads\(\s*id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\s+board_id BIGINT NOT NULL,\s+locked BOOL NOT NULL DEFAULT FALSE,\s+stickied BOOL NOT NULL DEFAULT FALSE,\s+anchored BOOL NOT NULL DEFAULT FALSE,\s+cyclical BOOL NOT NULL DEFAULT FALSE,\s+last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+CONSTRAINT threads_board_id_fk\s+FOREIGN KEY\(board_id\) REFERENCES boards\(id\) ON DELETE CASCADE\s*\)`, `CREATE INDEX thread_deleted_index ON threads\(is_deleted\)`, - `CREATE TABLE posts\(\s+id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\s+thread_id BIGINT NOT NULL,\s+is_top_post BOOL NOT NULL DEFAULT FALSE,\s+ip VARCHAR\(45\) NOT NULL,\s+created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+name VARCHAR\(50\) NOT NULL DEFAULT '',\s+tripcode VARCHAR\(10\) NOT NULL DEFAULT '',\s+is_role_signature BOOL NOT NULL DEFAULT FALSE, email VARCHAR\(50\) NOT NULL DEFAULT '',\s+subject VARCHAR\(100\) NOT NULL DEFAULT '',\s+message TEXT NOT NULL,\s+message_raw TEXT NOT NULL,\s+password TEXT NOT NULL,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+banned_message TEXT,\s+flag VARCHAR\(45\) NOT NULL DEFAULT '',\s+country VARCHAR\(80\) NOT NULL DEFAULT '',\s+CONSTRAINT posts_thread_id_fk\s+FOREIGN KEY\(thread_id\) REFERENCES threads\(id\) ON DELETE CASCADE \)`, + `CREATE TABLE posts\(\s+id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\s+thread_id BIGINT NOT NULL,\s+is_top_post BOOL NOT NULL DEFAULT FALSE,\s+ip VARCHAR\(45\) NOT NULL,\s+created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+name VARCHAR\(50\) NOT NULL DEFAULT '',\s+tripcode VARCHAR\(10\) NOT NULL DEFAULT '',\s+is_secure_tripcode BOOL NOT NULL DEFAULT FALSE,\s+is_role_signature BOOL NOT NULL DEFAULT FALSE, email VARCHAR\(50\) NOT NULL DEFAULT '',\s+subject VARCHAR\(100\) NOT NULL DEFAULT '',\s+message TEXT NOT NULL,\s+message_raw TEXT NOT NULL,\s+password TEXT NOT NULL,\s+deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_deleted BOOL NOT NULL DEFAULT FALSE,\s+banned_message TEXT,\s+flag VARCHAR\(45\) NOT NULL DEFAULT '',\s+country VARCHAR\(80\) NOT NULL DEFAULT '',\s+CONSTRAINT posts_thread_id_fk\s+FOREIGN KEY\(thread_id\) REFERENCES threads\(id\) ON DELETE CASCADE \)`, `CREATE INDEX top_post_index ON posts\(is_top_post\)`, `CREATE TABLE files\(\s+id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\s+post_id BIGINT NOT NULL,\s+file_order INT NOT NULL,\s+original_filename VARCHAR\(255\) NOT NULL,\s+filename VARCHAR\(45\) NOT NULL,\s+checksum TEXT NOT NULL,\s+file_size INT NOT NULL,\s+is_spoilered BOOL NOT NULL,\s+thumbnail_width INT NOT NULL,\s+thumbnail_height INT NOT NULL,\s+width INT NOT NULL,\s+height INT NOT NULL,\s+CONSTRAINT files_post_id_fk\s+FOREIGN KEY\(post_id\) REFERENCES posts\(id\) ON DELETE CASCADE,\s+CONSTRAINT files_post_id_file_order_unique UNIQUE\(post_id, file_order\) \)`, `CREATE TABLE staff\(\s+id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\s+username VARCHAR\(45\) NOT NULL,\s+password_checksum VARCHAR\(120\) NOT NULL,\s+global_rank INT,\s+added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\s+is_active BOOL NOT NULL DEFAULT TRUE,\s+CONSTRAINT staff_username_unique UNIQUE\(username\) \)`, diff --git a/pkg/gcsql/threads.go b/pkg/gcsql/threads.go index 6e66e6dc..d726fad7 100644 --- a/pkg/gcsql/threads.go +++ b/pkg/gcsql/threads.go @@ -173,8 +173,8 @@ func (t *Thread) GetPosts(repliesOnly bool, boardPage bool, limit int) ([]Post, var post Post if err = rows.Scan( &post.ID, &post.ThreadID, &post.IsTopPost, &post.IP, &post.CreatedOn, &post.Name, - &post.Tripcode, &post.IsRoleSignature, &post.Email, &post.Subject, &post.Message, - &post.MessageRaw, &post.Password, &post.DeletedAt, &post.IsDeleted, + &post.Tripcode, &post.IsSecureTripcode, &post.IsRoleSignature, &post.Email, &post.Subject, + &post.Message, &post.MessageRaw, &post.Password, &post.DeletedAt, &post.IsDeleted, &post.BannedMessage, &post.Flag, &post.Country, ); err != nil { return posts, err diff --git a/pkg/posting/post.go b/pkg/posting/post.go index fce113d2..9da19a4b 100644 --- a/pkg/posting/post.go +++ b/pkg/posting/post.go @@ -236,7 +236,7 @@ func getPostFromRequest(request *http.Request, boardConfig *config.BoardConfig, } } post.Name, post.Tripcode = ParseName(request.PostFormValue("postname"), boardConfig) - post.IsSecureTripcode = strings.Contains(post.Tripcode, "##") + post.IsSecureTripcode = strings.Contains(request.PostFormValue("postname"), "##") post.Email, _ = getEmailAndCommand(request) password := request.PostFormValue("postpassword") diff --git a/pkg/posting/post_test.go b/pkg/posting/post_test.go index 48e35c3d..f1e37970 100644 --- a/pkg/posting/post_test.go +++ b/pkg/posting/post_test.go @@ -54,7 +54,7 @@ func TestParseName(t *testing.T) { { nameAndTrip: "Name##notReserved", expectedName: "Name", - expectedTripcode: "MDlhNmNmYj", + expectedTripcode: "MGU5NDdiYm", }, } for _, tC := range testCases { diff --git a/templates/manage_recentposts.html b/templates/manage_recentposts.html index 15dcfacf..da6b6dd3 100644 --- a/templates/manage_recentposts.html +++ b/templates/manage_recentposts.html @@ -17,7 +17,7 @@ Post Name: {{- if and (eq $post.Name "") (eq $post.Tripcode "")}}Anonymous{{end}} {{- if ne $post.Name ""}}{{$post.Name}}{{end -}} - {{- if ne $post.Tripcode ""}}!{{$post.Tripcode}}{{end -}}
+ {{- if ne $post.Tripcode ""}}{{if $post.IsSecureTripcode}}!{{end}}!{{$post.Tripcode}}{{end -}}
IP: {{$post.IP}}
Board: /{{$post.BoardDir}}/ diff --git a/templates/post.html b/templates/post.html index f651a11c..6a293292 100644 --- a/templates/post.html +++ b/templates/post.html @@ -17,7 +17,7 @@ {{.post.Name}} {{- end -}} {{- if ne .post.Email ""}}{{end}} - {{- if ne .post.Tripcode ""}}!{{.post.Tripcode}}{{end -}} + {{- if ne .post.Tripcode ""}}{{if .post.IsSecureTripcode}}!{{end}}!{{.post.Tripcode}}{{end -}} {{- if .global.boardConfig.ShowPosterID -}} {{$uniqueID := .post.ThreadUniqueID}} (ID: {{$uniqueID}}) diff --git a/templates/post_edit.html b/templates/post_edit.html index b80d7acc..1c6a906e 100644 --- a/templates/post_edit.html +++ b/templates/post_edit.html @@ -25,7 +25,7 @@ function uploadThumbnailChanged(browseEl) { - +
Name{{stringAppend .post.Name "!" .post.Tripcode}}
Name{{.post.Name}}{{if ne .post.Tripcode ""}}{{if .post.IsSecureTripcode}}!{{end}}!{{.post.Tripcode}}{{end}}
Email
Subject