Modlogs / Adminlogs WIP, not much to see here. I'm just dumping this here, as I'm going to be moving a lot of code into another file, and I didn't want it to mess with the diffs.

This commit is contained in:
Azareal 2017-04-05 15:05:37 +01:00
parent 2dbeef4694
commit d3d76d407b
5 changed files with 70 additions and 0 deletions

View File

@ -169,6 +169,22 @@ CREATE TABLE `themes`(
unique(`uname`)
);
CREATE TABLE `moderation_logs`(
`action` varchar(100) not null,
`elementID` int not null,
`elementType` varchar(100) not null,
`ipaddress` varchar(200) not null,
`actorID` int not null
);
CREATE TABLE `administration_logs`(
`action` varchar(100) not null,
`elementID` int not null,
`elementType` varchar(100) not null,
`ipaddress` varchar(200) not null,
`actorID` int not null
);
INSERT INTO settings(`name`,`content`,`type`) VALUES ('url_tags','1','bool');
INSERT INTO settings(`name`,`content`,`type`,`constraints`) VALUES ('activation_type','1','list','1-3');
INSERT INTO settings(`name`,`content`,`type`) VALUES ('bigpost_min_chars','250','int');

View File

@ -73,6 +73,12 @@ func route_edit_topic(w http.ResponseWriter, r *http.Request) {
} else {
action = "unlock"
}
err = addModLog(action,tid,"topic",ipaddress,user.ID)
if err != nil {
InternalError(err,w,r)
return
}
_, err = create_action_reply_stmt.Exec(tid,action,ipaddress,user.ID)
if err != nil {
InternalError(err,w,r)
@ -137,6 +143,23 @@ func route_delete_topic(w http.ResponseWriter, r *http.Request) {
InternalError(err,w,r)
return
}
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
LocalError("Bad IP",w,r,user)
return
}
err = addModLog("delete",tid,"topic",ipaddress,user.ID)
if err != nil {
InternalError(err,w,r)
return
}
/*_, err = create_action_reply_stmt.Exec(tid,"delete",ipaddress,user.ID)
if err != nil {
InternalError(err,w,r)
return
}*/
log.Print("The topic '" + strconv.Itoa(tid) + "' was deleted by User ID #" + strconv.Itoa(user.ID) + ".")
http.Redirect(w,r,"/",http.StatusSeeOther)

View File

@ -91,6 +91,8 @@ var update_group_stmt *sql.Stmt
var create_group_stmt *sql.Stmt
var add_theme_stmt *sql.Stmt
var update_theme_stmt *sql.Stmt
var add_modlog_entry_stmt *sql.Stmt
var add_adminlog_entry_stmt *sql.Stmt
func init_database(err error) {
if(dbpassword != ""){
@ -594,6 +596,18 @@ func init_database(err error) {
log.Fatal(err)
}
log.Print("Preparing add_modlog_entry statement.")
add_modlog_entry_stmt, err = db.Prepare("INSERT INTO moderation_logs(action,elementID,elementType,ipaddress,actorID) VALUES(?,?,?,?,?)")
if err != nil {
log.Fatal(err)
}
log.Print("Preparing add_adminlog_entry statement.")
add_adminlog_entry_stmt, err = db.Prepare("INSERT INTO moderation_logs(action,elementID,elementType,actorID) VALUES(?,?,?,?)")
if err != nil {
log.Fatal(err)
}
log.Print("Loading the usergroups.")
groups = append(groups, Group{ID:0,Name:"System"})

View File

@ -15,6 +15,7 @@ import "net/http"
import "html"
import "html/template"
import "database/sql"
import _ "github.com/go-sql-driver/mysql"
import "golang.org/x/crypto/bcrypt"

View File

@ -223,3 +223,19 @@ func fill_group_id_gap(biggerID int, smallerID int) {
groups = append(groups, dummy)
}
}
func addModLog(action string, elementID int, elementType string, ipaddress string, actorID int) error {
_, err := add_modlog_entry_stmt.Exec(action,elementID,elementType,ipaddress,actorID)
if err != nil {
return err
}
return nil
}
func addAdminLog(action string, elementID string, elementType int, ipaddress string, actorID int) error {
_, err := add_adminlog_entry_stmt.Exec(action,elementID,elementType,ipaddress,actorID)
if err != nil {
return err
}
return nil
}