mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 03:36:22 -07:00
fix errors on post/thread deletion, delete images attached to deleted posts/threads
This commit is contained in:
parent
9f57d0f063
commit
b56683abe5
7 changed files with 74 additions and 44 deletions
|
@ -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,
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
version float32 = 0.6
|
||||
version float32 = 0.7
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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() + "<br />"
|
||||
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()+"<br />"
|
||||
}
|
||||
|
@ -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()+"<br />"
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package main
|
||||
|
||||
// #define _GNU_SOURCE
|
||||
// #include <stdio.h>
|
||||
// #include <unistd.h>
|
||||
// #include <sys/types.h>
|
||||
import "C"
|
||||
|
||||
var pid uintptr
|
||||
/*
|
||||
func fork() int {
|
||||
return C.GoInt(C.fork())
|
||||
}
|
||||
|
||||
func setsid() {
|
||||
C.setsid()
|
||||
}*/
|
|
@ -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<br />",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<br />\n<meta http-equiv=\"refresh\" content=\"1;url=http://lunachan.net/test/\">", post)
|
||||
writer.Header().Add("refresh", "3;url=" + request.Referer())
|
||||
fmt.Fprintf(writer, "Attached image from %s deleted successfully<br />\n<meta http-equiv=\"refresh\" content=\"1;url=" + config.DocumentRoot + "/" + board + "/\">", 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<br />", post)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<div class="file-deleted-box" style="text-align:center;">File removed</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<input type="checkbox" id="check{{$op.ID}}" name="check{{$op.ID}}" /><label class="post-info" for="check{{$op.ID}}"> <span class="subject">{{$op.Subject}}</span> <span class="postername">{{if stringNeq $op.Email ""}}<a href="mailto:{{$op.Email}}">{{end}}{{if stringNeq $op.Name ""}}{{$op.Name}}{{else}}{{if stringEq $op.Tripcode ""}}{{$board.Anonymous}}{{end}}{{end}}{{if stringNeq $op.Email ""}}</a>{{end}}</span>{{if stringNeq $op.Tripcode ""}}<span class="tripcode">!{{$op.Tripcode}}</span>{{end}} {{formatTimestamp $op.Timestamp}} </label><a href="/{{$board.Dir}}/res/{{$op.ID}}.html#{{$op.ID}}">No.</a> <a href="/{{$board.Dir}}/res/{{$op.ID}}.html#i{{$op.ID}}">{{$op.ID}}</a> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">▼</a>]</span> <span>[<a href="/{{$board.Dir}}/res/{{$op.ID}}.html">View</a>]</span></span><br />
|
||||
<input type="checkbox" id="check{{$op.ID}}" name="check{{$op.ID}}" /><label class="post-info" for="check{{$op.ID}}"> <span class="subject">{{$op.Subject}}</span> <span class="postername">{{if stringNeq $op.Email ""}}<a href="mailto:{{$op.Email}}">{{end}}{{if stringNeq $op.Name ""}}{{$op.Name}}{{else}}{{if stringEq $op.Tripcode ""}}{{$board.Anonymous}}{{end}}{{end}}{{if stringNeq $op.Email ""}}</a>{{end}}</span>{{if stringNeq $op.Tripcode ""}}<span class="tripcode">!{{$op.Tripcode}}</span>{{end}} {{formatTimestamp $op.Timestamp}} </label><a href="/{{$board.Dir}}/res/{{$op.ID}}.html#{{$op.ID}}">No.</a> <a href="/{{$board.Dir}}/res/{{$op.ID}}.html#i{{$op.ID}}">{{$op.ID}}</a> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">▼</a>]</span></span><br />
|
||||
<div class="post-text">
|
||||
{{if stringNeq $op.Message ""}}
|
||||
<div class="post-text">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue