diff --git a/initialsetupdb.sql b/initialsetupdb.sql index b10ef80d..73027978 100644 --- a/initialsetupdb.sql +++ b/initialsetupdb.sql @@ -37,7 +37,7 @@ CREATE TABLE `DBPREFIXbannedhashes` ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE `DBPREFIXboards` ( - `id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, `order` TINYINT UNSIGNED NOT NULL DEFAULT 0, `dir` VARCHAR(45) NOT NULL, `type` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, @@ -125,7 +125,7 @@ CREATE TABLE `DBPREFIXpollresults` ( CREATE TABLE `DBPREFIXposts` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `boardid` TINYINT(3) UNSIGNED NOT NULL, + `boardid` INT NOT NULL, `parentid` INT(10) UNSIGNED NOT NULL DEFAULT '0', `name` VARCHAR(45) NOT NULL, `tripcode` CHAR(10) NOT NULL, diff --git a/src/gochan.go b/src/gochan.go index 488896bf..376a1f89 100644 --- a/src/gochan.go +++ b/src/gochan.go @@ -5,7 +5,7 @@ import ( ) var ( - version float32 = 0.6 + version float32 = 0.7 ) diff --git a/src/posting.go b/src/posting.go index 6fd32b96..d3ea1eff 100644 --- a/src/posting.go +++ b/src/posting.go @@ -50,7 +50,7 @@ func buildBoardPage(boardid int, boards []BoardsTable, sections []interface{}) ( var interfaces []interface{} var threads []interface{} var op_posts []interface{} - op_posts,err := getPostArr("SELECT * FROM `"+config.DBprefix+"posts` WHERE `boardid` = "+strconv.Itoa(board.ID)+" AND `parentid` = 0 ORDER BY `bumped` DESC LIMIT "+strconv.Itoa(config.ThreadsPerPage_img)) + op_posts,err := getPostArr("SELECT * FROM `"+config.DBprefix+"posts` WHERE `boardid` = "+strconv.Itoa(board.ID)+" AND `parentid` = 0 AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `bumped` DESC LIMIT "+strconv.Itoa(config.ThreadsPerPage_img)) if err != nil { html += err.Error() + "
" op_posts = make([]interface{},0) @@ -65,7 +65,7 @@ func buildBoardPage(boardid int, boards []BoardsTable, sections []interface{}) ( if op_post.Stickied { thread.IName = "thread" - posts_in_thread,err = getPostArr("SELECT * FROM `"+config.DBprefix+"posts` WHERE `boardid` = "+strconv.Itoa(board.ID)+" AND `parentid` = "+strconv.Itoa(op_post.ID)+" ORDER BY `id` DESC LIMIT "+strconv.Itoa(config.StickyRepliesOnBoardPage)) + posts_in_thread,err = getPostArr("SELECT * FROM `"+config.DBprefix+"posts` WHERE `boardid` = "+strconv.Itoa(board.ID)+" AND `parentid` = "+strconv.Itoa(op_post.ID)+" AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `id` DESC LIMIT "+strconv.Itoa(config.StickyRepliesOnBoardPage)) if err != nil { html += err.Error()+"
" } @@ -89,7 +89,7 @@ func buildBoardPage(boardid int, boards []BoardsTable, sections []interface{}) ( if !op_post.Stickied { thread.IName = "thread" - posts_in_thread,err = getPostArr("SELECT * FROM (SELECT * FROM `"+config.DBprefix+"posts` WHERE `boardid` = "+strconv.Itoa(board.ID)+" AND `parentid` = "+strconv.Itoa(op_post.ID)+" order by `id` DESC LIMIT "+strconv.Itoa(config.RepliesOnBoardpage)+") t ORDER BY `id` ASC") + posts_in_thread,err = getPostArr("SELECT * FROM (SELECT * FROM `"+config.DBprefix+"posts` WHERE `boardid` = "+strconv.Itoa(board.ID)+" AND `parentid` = "+strconv.Itoa(op_post.ID)+" AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `id` DESC LIMIT "+strconv.Itoa(config.RepliesOnBoardpage)+") t ORDER BY `id` ASC") if err != nil { html += err.Error()+"
" } diff --git a/src/process.go b/src/process.go deleted file mode 100644 index e9bb86f5..00000000 --- a/src/process.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -// #define _GNU_SOURCE -// #include -// #include -// #include -import "C" - -var pid uintptr -/* -func fork() int { - return C.GoInt(C.fork()) -} - -func setsid() { - C.setsid() -}*/ \ No newline at end of file diff --git a/src/server.go b/src/server.go index e90395e9..d9771868 100644 --- a/src/server.go +++ b/src/server.go @@ -176,6 +176,7 @@ func validReferrer(request http.Request) (valid bool) { func utilHandler(writer http.ResponseWriter, request *http.Request, data interface{}) { action := request.FormValue("action") board := request.FormValue("board") + var err error if action == "" && request.PostFormValue("delete_btn") != "Delete" && request.PostFormValue("report_btn") != "Report" { http.Redirect(writer,request,path.Join(config.SiteWebfolder,"/"),http.StatusFound) return @@ -187,6 +188,7 @@ func utilHandler(writer http.ResponseWriter, request *http.Request, data interfa } } if request.PostFormValue("delete_btn") == "Delete" { + // Delete a post or thread file_only := request.FormValue("fileonly") == "on" password := md5_sum(request.FormValue("password")) rank := getStaffRank() @@ -202,12 +204,13 @@ func utilHandler(writer http.ResponseWriter, request *http.Request, data interfa var filetype string var password_checksum string var board_id int - post_int,err := strconv.Atoi(post) + //post_int,err := strconv.Atoi(post) - err = db.QueryRow("SELECT `parentid`,`filename`,`password` FROM `"+config.DBprefix+"posts` WHERE `id` = "+post).Scan(&parent_id,&filename,&password_checksum) + err = db.QueryRow("SELECT `parentid`,`filename`,`password` FROM `" + config.DBprefix + "posts` WHERE `id` = " + post + " AND `deleted_timestamp` = '" + nil_timestamp + "'").Scan(&parent_id, &filename, &password_checksum) if err == sql.ErrNoRows { //the post has already been deleted - fmt.Fprintf(writer, "%s has already been deleted\n",post) + writer.Header().Add("refresh", "3;url=" + request.Referer()) + fmt.Fprintf(writer, "%s has already been deleted or is a post in a deleted thread.\n
",post) continue } if err != nil { @@ -215,7 +218,7 @@ func utilHandler(writer http.ResponseWriter, request *http.Request, data interfa return } - err = db.QueryRow("SELECT `id` FROM `"+config.DBprefix+"boards` WHERE `dir` = '"+board+"'").Scan(&board_id) + err = db.QueryRow("SELECT `id` FROM `" + config.DBprefix + "boards` WHERE `dir` = '" + board + "'").Scan(&board_id) if err != nil { server.ServeErrorPage(writer,err.Error()) return @@ -240,30 +243,51 @@ func utilHandler(writer http.ResponseWriter, request *http.Request, data interfa server.ServeErrorPage(writer,err.Error()) return } - _,err = db.Exec("UPDATE `"+config.DBprefix+"posts` SET `filename` = 'deleted' WHERE `id` = "+post) + _,err = db.Exec("UPDATE `" + config.DBprefix + "posts` SET `filename` = 'deleted' WHERE `id` = " + post) if err != nil { - server.ServeErrorPage(writer,err.Error()) + server.ServeErrorPage(writer, err.Error()) return } } - fmt.Fprintf(writer, "Attached image from %s deleted successfully
\n", post) + writer.Header().Add("refresh", "3;url=" + request.Referer()) + fmt.Fprintf(writer, "Attached image from %s deleted successfully
\n", post) } else { - if parent_id > 0 { - os.Remove(path.Join(config.DocumentRoot,board,"/res/index.html")) - } - _,err = db.Exec("DELETE FROM `"+config.DBprefix+"posts` WHERE `id` = "+post) + + // delete the post + _,err = db.Exec("UPDATE `" + config.DBprefix + "posts` SET `deleted_timestamp` = '" + getSQLDateTime() + "' WHERE `id` = " + post) if parent_id == 0 { - err = buildThread(post_int, board_id) + err = os.Remove(path.Join(config.DocumentRoot, board, "/res/" + post + ".html")) } else { err = buildThread(parent_id,board_id) } + // if the deleted post is actually a thread, delete its posts + _,_ = db.Exec("UPDATE `" + config.DBprefix + "posts` SET `deleted_timestamp` = '" + getSQLDateTime() + "' WHERE `parentid` = " + post) if err != nil { server.ServeErrorPage(writer,err.Error()) return } - fmt.Fprintf(writer, "%s deleted successfully\n", post) - writer.Header().Add("refresh", "5;url="+request.Referer()) + + // delete the + var deleted_filename string + err = db.QueryRow("SELECT `filename` FROM `" + config.DBprefix + "posts` WHERE `id` = " + post + " AND `filename` != ''").Scan(&deleted_filename) + if err == nil { + os.Remove(path.Join(config.DocumentRoot, board, "/src/", deleted_filename)) + os.Remove(path.Join(config.DocumentRoot, board, "/thumb/", strings.Replace(deleted_filename, ".", "t.",-1))) + os.Remove(path.Join(config.DocumentRoot, board, "/thumb/", strings.Replace(deleted_filename, ".", "c.",-1))) + } + + err = db.QueryRow("SELECT `filename` FROM `" + config.DBprefix + "posts` WHERE `parentid` = " + post + " AND `filename` != ''").Scan(&deleted_filename) + if err == nil { + os.Remove(path.Join(config.DocumentRoot, board, "/src/", deleted_filename)) + os.Remove(path.Join(config.DocumentRoot, board, "/thumb/", strings.Replace(deleted_filename, ".", "t.",-1))) + os.Remove(path.Join(config.DocumentRoot, board, "/thumb/", strings.Replace(deleted_filename, ".", "c.",-1))) + } + + buildBoardPage(board_id, getBoardArr(""), getSectionArr("")) + + writer.Header().Add("refresh", "3;url=" + request.Referer()) + fmt.Fprintf(writer, "%s deleted successfully\n
", post) } } } diff --git a/src/template.go b/src/template.go index 5ab3ce77..e9dba3e4 100644 --- a/src/template.go +++ b/src/template.go @@ -109,7 +109,11 @@ var funcMap = template.FuncMap{ } index := strings.LastIndex(img, ".") return img[0:index]+"t."+filetype - + }, + "printValue": func(i interface{}) int { + fmt.Println("interface: ", i.(string)) + fmt.Println("value: ", i) + return 0 }, } @@ -147,7 +151,9 @@ func initTemplates() { fmt.Println("Failed loading template \""+config.TemplateDir+"/banpage.html\": " + tmpl_err.Error()) os.Exit(2) } - banpage_tmpl_str = "{{$config := getInterface .Data 0}}{{$ban := getInterface .Data 1}}" + string(banpage_tmpl_bytes) + banpage_tmpl_str = "{{$config := getInterface .Data 0}}" + + "{{$ban := getInterface .Data 1}}" + + string(banpage_tmpl_bytes) banpage_tmpl,tmpl_err = template.New("banpage_tmpl").Funcs(funcMap).Parse(string(banpage_tmpl_str)) if tmpl_err != nil { fmt.Println("Failed loading template \""+config.TemplateDir+"/banpage.html\": " + tmpl_err.Error()) @@ -180,10 +186,16 @@ func initTemplates() { img_boardpage_tmpl_bytes,_ := ioutil.ReadFile(path.Join(config.TemplateDir,"img_boardpage.html")) if tmpl_err != nil { - fmt.Println("Failed loading template \""+config.TemplateDir+"/img_boardpage.html\": " + tmpl_err.Error()) + fmt.Println("Failed loading template \"" + config.TemplateDir+"/img_boardpage.html\": " + tmpl_err.Error()) os.Exit(2) } - img_boardpage_tmpl_str = "{{$config := getInterface .Data 0}}{{$board_arr := getInterface .Data 1}}{{$section_arr := getInterface .Data 2}}{{$thread_arr := getInterface .Data 3}}{{$board_info := getInterface .Data 4}}{{$board := getInterface $board_info.Data 0}}" + string(img_boardpage_tmpl_bytes) + img_boardpage_tmpl_str = "{{$config := getInterface .Data 0}}" + + "{{$board_arr := getInterface .Data 1}}" + + "{{$section_arr := getInterface .Data 2}}" + + "{{$thread_arr := getInterface .Data 3}}" + + "{{$board_info := getInterface .Data 4}}" + + "{{$board := getInterface $board_info.Data 0}}" + + string(img_boardpage_tmpl_bytes) img_boardpage_tmpl,tmpl_err = template.New("img_boardpage_tmpl").Funcs(funcMap).Parse(img_boardpage_tmpl_str) if tmpl_err != nil { fmt.Println("Failed loading template \""+config.TemplateDir+"/img_boardpage.html: \"" + tmpl_err.Error()) @@ -195,7 +207,14 @@ func initTemplates() { fmt.Println("Failed loading template \""+config.TemplateDir+"/img_thread.html\": " + tmpl_err.Error()) os.Exit(2) } - img_thread_tmpl_str = "{{$config := getInterface .Data 0}}{{$post_arr := getInterface .Data 1}}{{$board_arr := getInterface .Data 2}}{{$section_arr := getInterface .Data 3}}{{$op := getInterface $post_arr 0}}{{$boardid := subtract $op.BoardID 1}}{{$board := getInterface $board_arr.Data $boardid}}" + string(img_thread_tmpl_bytes) + img_thread_tmpl_str = "{{$config := getInterface .Data 0}}" + + "{{$post_arr := getInterface .Data 1}}" + + "{{$board_arr := getInterface .Data 2}}" + + "{{$section_arr := getInterface .Data 3}}" + + "{{$op := getInterface $post_arr 0}}" + + "{{$boardid := subtract $op.BoardID 1}}" + + "{{$board := getInterface $board_arr.Data $boardid}}" + + string(img_thread_tmpl_bytes) img_thread_tmpl,tmpl_err = template.New("img_thread_tmpl").Funcs(funcMap).Parse(img_thread_tmpl_str) if tmpl_err != nil { fmt.Println("Failed loading template \""+config.TemplateDir+"/img_thread.html: \"" + tmpl_err.Error()) @@ -218,7 +237,11 @@ func initTemplates() { fmt.Println(err.Error()) os.Exit(2) } - front_page_tmpl_str = "{{$config := getInterface .Data 0}}{{$page_arr := getInterface .Data 1}}{{$board_arr := getInterface .Data 2}}{{$section_arr := getInterface .Data 3}}" + string(front_page_tmpl_bytes) + front_page_tmpl_str = "{{$config := getInterface .Data 0}}" + + "{{$page_arr := getInterface .Data 1}}" + + "{{$board_arr := getInterface .Data 2}}" + + "{{$section_arr := getInterface .Data 3}}" + + string(front_page_tmpl_bytes) front_page_tmpl,tmpl_err = template.New("front_page_tmpl").Funcs(funcMap).Parse(front_page_tmpl_str) if tmpl_err != nil { fmt.Println("Failed loading template \""+config.TemplateDir+"/front.html\": "+tmpl_err.Error()) diff --git a/templates/img_thread.html b/templates/img_thread.html index 6bd8c662..194c47a7 100644 --- a/templates/img_thread.html +++ b/templates/img_thread.html @@ -63,7 +63,7 @@
File removed
{{end}} {{end}} - No. {{$op.ID}} [] [View]
+ No. {{$op.ID}} []
{{if stringNeq $op.Message ""}}