From 3662a298d4b40a5c33a8db3679823db6572fe8d6 Mon Sep 17 00:00:00 2001 From: Azareal Date: Wed, 15 Mar 2017 08:34:14 +0000 Subject: [PATCH] Added support for authenticated SMTP. I'm going to do a few tests on this tonight. Added 87 new emoji shortcodes. We now have all of the Unicode v1.1 emojis covered. Added support for #fid hashlinks. Added the :(, :O, :o, and :p smiley codes. Fixed a bug where the topic data wasn't getting updated after creating a reply. Added the get_forum function. Added the get_forum_copy function. Added the build_forum_url function. --- config.go | 4 ++ data.sql | 7 +++ forum.go | 23 +++++++-- install/install.go | 4 ++ pages.go | 125 +++++++++++++++++++++++++++++++++++++++++---- routes.go | 10 ++++ utils.go | 8 +++ 7 files changed, 167 insertions(+), 14 deletions(-) diff --git a/config.go b/config.go index bab4efe3..97b9d4e8 100644 --- a/config.go +++ b/config.go @@ -21,8 +21,12 @@ var staff_css = " background-color: #ffeaff;" var uncategorised_forum_visible = true var enable_emails = false var site_name = "Test Install" // Should be a setting + var site_email = "" // Should be a setting var smtp_server = "" +var smtp_username = "" +var smtp_password = "" + //var noavatar = "https://api.adorable.io/avatars/{width}/{id}@{site_url}.png" var noavatar = "https://api.adorable.io/avatars/285/{id}@" + site_url + ".png" var items_per_page = 25 diff --git a/data.sql b/data.sql index 2fd1289a..c5a0874d 100644 --- a/data.sql +++ b/data.sql @@ -98,6 +98,13 @@ CREATE TABLE `replies`( primary key(`rid`) ) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; +CREATE TABLE `revisions`( + `index` int not null, + `content` text not null, + `contentID` int not null, + `contentType` varchar(100) DEFAULT 'replies' not null +) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; + CREATE TABLE `users_replies`( `rid` int not null AUTO_INCREMENT, `uid` int not null, diff --git a/forum.go b/forum.go index c465d9fd..7561eaf6 100644 --- a/forum.go +++ b/forum.go @@ -1,5 +1,6 @@ package main //import "fmt" +import "strconv" import "database/sql" import _ "github.com/go-sql-driver/mysql" @@ -78,10 +79,24 @@ func delete_forum(fid int) error { return nil } +func get_forum(fid int) (forum *Forum, res bool) { + if !((fid <= forumCapCount) && (fid >= 0) && forums[fid].Name!="") { + return forum, false + } + return &forums[fid], true +} + +func get_forum_copy(fid int) (forum Forum, res bool) { + if !((fid <= forumCapCount) && (fid >= 0) && forums[fid].Name!="") { + return forum, false + } + return forums[fid], true +} + func forum_exists(fid int) bool { - //fmt.Println(fid) - //fmt.Println(fid <= forumCapCount) - //fmt.Println(fid >= 0) - //fmt.Println(forums[fid].Name!="") return (fid <= forumCapCount) && (fid >= 0) && forums[fid].Name!="" } + +func build_forum_url(fid int) string { + return "/forum/" + strconv.Itoa(fid) +} diff --git a/install/install.go b/install/install.go index 71d74ff3..ad7b2b4f 100644 --- a/install/install.go +++ b/install/install.go @@ -159,8 +159,12 @@ var staff_css = " background-color: #ffeaff;" var uncategorised_forum_visible = true var enable_emails = false var site_name = "` + site_name + `" // Should be a setting + var site_email = "" // Should be a setting var smtp_server = "" +var smtp_username = "" +var smtp_password = "" + //var noavatar = "https://api.adorable.io/avatars/{width}/{id}@{site_url}.png" var noavatar = "https://api.adorable.io/avatars/285/{id}@" + site_url + ".png" var items_per_page = 25 diff --git a/pages.go b/pages.go index 6c9fc695..c5b0227f 100644 --- a/pages.go +++ b/pages.go @@ -103,6 +103,7 @@ var http_prot_b []byte = []byte("http://") var invalid_url []byte = []byte("[Invalid URL]") var invalid_topic []byte = []byte("[Invalid Topic]") var invalid_profile []byte = []byte("[Invalid Profile]") +var invalid_forum []byte = []byte("[Invalid Forum]") var url_open []byte = []byte("") var bytes_singlequote []byte = []byte("'") @@ -156,6 +157,94 @@ func shortcode_to_unicode(msg string) string { msg = strings.Replace(msg,":relieved:","😌",-1) msg = strings.Replace(msg,":nerd:","🤓",-1) msg = strings.Replace(msg,":stuck_out_tongue:","😛",-1) + msg = strings.Replace(msg,":worried:","😟",-1) + msg = strings.Replace(msg,":drooling_face:","🤤",-1) + msg = strings.Replace(msg,":disappointed:","😞",-1) + msg = strings.Replace(msg,":astonished:","😲",-1) + msg = strings.Replace(msg,":slight_frown:","🙁",-1) + msg = strings.Replace(msg,":skull_crossbones:","☠ī¸",-1) + msg = strings.Replace(msg,":skull:","💀",-1) + msg = strings.Replace(msg,":point_up:","☝ī¸",-1) + msg = strings.Replace(msg,":v:","✌ī¸ī¸",-1) + msg = strings.Replace(msg,":writing_hand:","✍ī¸",-1) + msg = strings.Replace(msg,":heart:","❤ī¸ī¸",-1) + msg = strings.Replace(msg,":heart_exclamation:","âŖī¸",-1) + msg = strings.Replace(msg,":hotsprings:","♨ī¸",-1) + msg = strings.Replace(msg,":airplane:","✈ī¸ī¸",-1) + msg = strings.Replace(msg,":hourglass:","⌛",-1) + msg = strings.Replace(msg,":watch:","⌚",-1) + msg = strings.Replace(msg,":comet:","☄ī¸",-1) + msg = strings.Replace(msg,":snowflake:","❄ī¸",-1) + msg = strings.Replace(msg,":cloud:","☁ī¸",-1) + msg = strings.Replace(msg,":sunny:","☀ī¸",-1) + msg = strings.Replace(msg,":spades:","♠ī¸",-1) + msg = strings.Replace(msg,":hearts:","â™Ĩī¸ī¸",-1) + msg = strings.Replace(msg,":diamonds:","â™Ļī¸",-1) + msg = strings.Replace(msg,":clubs:","â™Ŗī¸",-1) + msg = strings.Replace(msg,":phone:","☎ī¸",-1) + msg = strings.Replace(msg,":telephone:","☎ī¸",-1) + msg = strings.Replace(msg,":biohazard:","â˜Ŗī¸",-1) + msg = strings.Replace(msg,":radioactive:","â˜ĸī¸",-1) + msg = strings.Replace(msg,":scissors:","✂ī¸",-1) + msg = strings.Replace(msg,":arrow_upper_right:","↗ī¸",-1) + msg = strings.Replace(msg,":arrow_right:","➡ī¸",-1) + msg = strings.Replace(msg,":arrow_lower_right:","↘ī¸",-1) + msg = strings.Replace(msg,":arrow_lower_left:","↙ī¸",-1) + msg = strings.Replace(msg,":arrow_upper_left:","↖ī¸",-1) + msg = strings.Replace(msg,":arrow_up_down:","↕ī¸",-1) + msg = strings.Replace(msg,":left_right_arrow:","↔ī¸",-1) + msg = strings.Replace(msg,":leftwards_arrow_with_hook:","↩ī¸",-1) + msg = strings.Replace(msg,":arrow_right_hook:","â†Ēī¸",-1) + msg = strings.Replace(msg,":arrow_forward:","â–ļī¸",-1) + msg = strings.Replace(msg,":arrow_backward:","◀ī¸",-1) + msg = strings.Replace(msg,":female:","♀ī¸",-1) + msg = strings.Replace(msg,":male:","♂ī¸",-1) + msg = strings.Replace(msg,":ballot_box_with_check:","☑ī¸",-1) + msg = strings.Replace(msg,":heavy_check_mark:","✔ī¸ī¸",-1) + msg = strings.Replace(msg,":heavy_multiplication_x:","✖ī¸",-1) + msg = strings.Replace(msg,":pisces:","♓",-1) + msg = strings.Replace(msg,":aquarius:","♒",-1) + msg = strings.Replace(msg,":capricorn:","♑",-1) + msg = strings.Replace(msg,":sagittarius:","♐",-1) + msg = strings.Replace(msg,":scorpius:","♏",-1) + msg = strings.Replace(msg,":libra:","♎",-1) + msg = strings.Replace(msg,":virgo:","♍",-1) + msg = strings.Replace(msg,":leo:","♌",-1) + msg = strings.Replace(msg,":cancer:","♋",-1) + msg = strings.Replace(msg,":gemini:","♊",-1) + msg = strings.Replace(msg,":taurus:","♉",-1) + msg = strings.Replace(msg,":aries:","♈",-1) + msg = strings.Replace(msg,":peace:","☎ī¸",-1) + msg = strings.Replace(msg,":eight_spoked_asterisk:","âœŗī¸",-1) + msg = strings.Replace(msg,":eight_pointed_black_star:","✴ī¸",-1) + msg = strings.Replace(msg,":snowman2:","☃ī¸",-1) + msg = strings.Replace(msg,":umbrella2:","☂ī¸",-1) + msg = strings.Replace(msg,":pencil2:","✏ī¸",-1) + msg = strings.Replace(msg,":black_nib:","✒ī¸",-1) + msg = strings.Replace(msg,":email:","✉ī¸",-1) + msg = strings.Replace(msg,":envelope:","✉ī¸",-1) + msg = strings.Replace(msg,":keyboard:","⌨ī¸",-1) + msg = strings.Replace(msg,":white_small_square:","â–Ģī¸",-1) + msg = strings.Replace(msg,":black_small_square:","â–Ēī¸",-1) + msg = strings.Replace(msg,":secret:","㊙ī¸",-1) + msg = strings.Replace(msg,":congratulations:","㊗ī¸",-1) + msg = strings.Replace(msg,":m:","Ⓜī¸",-1) + msg = strings.Replace(msg,":tm:","â„ĸī¸ī¸",-1) + msg = strings.Replace(msg,":registered:","ÂŽī¸",-1) + msg = strings.Replace(msg,":copyright:","Šī¸",-1) + msg = strings.Replace(msg,":wavy_dash:","〰ī¸",-1) + msg = strings.Replace(msg,":bangbang:","â€ŧī¸",-1) + msg = strings.Replace(msg,":sparkle:","❇ī¸",-1) + msg = strings.Replace(msg,":star_of_david:","✡ī¸",-1) + msg = strings.Replace(msg,":wheel_of_dharma:","☸ī¸",-1) + msg = strings.Replace(msg,":yin_yang:","☯ī¸",-1) + msg = strings.Replace(msg,":cross:","✝ī¸",-1) + msg = strings.Replace(msg,":orthodox_cross:","â˜Ļī¸",-1) + msg = strings.Replace(msg,":star_and_crescent:","â˜Ēī¸",-1) + msg = strings.Replace(msg,":frowning2:","☚ī¸",-1) + msg = strings.Replace(msg,":information_source:","ℹī¸",-1) + msg = strings.Replace(msg,":interrobang:","⁉ī¸",-1) + return msg } @@ -167,24 +256,20 @@ func preparse_message(msg string) string { return shortcode_to_unicode(msg) } -//var msg_index int = 0 func parse_message(msg string/*, user User*/) string { msg = strings.Replace(msg,":)","😀",-1) + msg = strings.Replace(msg,":(","😞",-1) msg = strings.Replace(msg,":D","😃",-1) msg = strings.Replace(msg,":P","😛",-1) + msg = strings.Replace(msg,":O","😲",-1) + msg = strings.Replace(msg,":p","😛",-1) + msg = strings.Replace(msg,":o","😲",-1) //msg = url_reg.ReplaceAllString(msg,"$2$3//$4") // Search for URLs, mentions and hashlinks in the messages... //fmt.Println("Parser Loop!") - //fmt.Println("Message Index:") - //msg_index++ - //fmt.Println(msg_index) var msgbytes = []byte(msg) var outbytes []byte - //fmt.Println("Outbytes Start:") - //fmt.Println(outbytes) - //fmt.Println(string(outbytes)) - //fmt.Println("Outbytes Start End:") msgbytes = append(msgbytes,space_gap...) //fmt.Println(`"`+string(msgbytes)+`"`) lastItem := 0 @@ -205,7 +290,6 @@ func parse_message(msg string/*, user User*/) string { if (i==0 && (msgbytes[0] > 32)) || ((msgbytes[i] < 33) && (msgbytes[i + 1] > 32)) { //fmt.Println("IN") //fmt.Println(msgbytes[i]) - //fmt.Println("STEP CONTINUE") if (i != 0) || msgbytes[i] < 33 { i++ } @@ -263,8 +347,29 @@ func parse_message(msg string/*, user User*/) string { outbytes = append(outbytes, rid_bit...) outbytes = append(outbytes, url_close...) lastItem = i + } else if bytes.Equal(msgbytes[i+1:i+5],[]byte("fid-")) { + outbytes = append(outbytes,msgbytes[lastItem:i]...) + i += 5 + start := i + fid, int_len := coerce_int_bytes(msgbytes[start:]) + i += int_len + + if !forum_exists(fid) { + outbytes = append(outbytes,invalid_forum...) + lastItem = i + continue + } + + outbytes = append(outbytes, url_open...) + var url_bit []byte = []byte(build_forum_url(fid)) + outbytes = append(outbytes, url_bit...) + outbytes = append(outbytes, url_open2...) + var fid_bit []byte = []byte("#fid-" + strconv.Itoa(fid)) + outbytes = append(outbytes, fid_bit...) + outbytes = append(outbytes, url_close...) + lastItem = i } else { - // TO-DO: Forum Link + // TO-DO: Forum Shortcode Link } } else if msgbytes[i]=='@' { //fmt.Println("IN @") diff --git a/routes.go b/routes.go index f2468be4..b52fc779 100644 --- a/routes.go +++ b/routes.go @@ -724,6 +724,16 @@ func route_create_reply(w http.ResponseWriter, r *http.Request) { return } + // Reload the topic... + err = topics.Load(tid) + if err != nil && err != sql.ErrNoRows { + LocalError("The destination no longer exists",w,r,user) + return + } else if err != nil { + InternalError(err,w,r) + return + } + http.Redirect(w,r,"/topic/" + strconv.Itoa(tid), http.StatusSeeOther) err = increase_post_user_stats(wcount, user.ID, false, user) if err != nil { diff --git a/utils.go b/utils.go index f7668b14..13d65fa2 100644 --- a/utils.go +++ b/utils.go @@ -87,6 +87,14 @@ func SendEmail(email string, subject string, msg string) bool { return false } + if smtp_username != "" { + auth := smtp.PlainAuth("",smtp_username,smtp_password,smtp_server) + err = con.Auth(auth) + if err != nil { + return false + } + } + email_data, err := con.Data() if err != nil { return false