Router Generator WIP

Added a test for one of the router algorithms.
Added the ViewAdminLogs permission. Adminlogs are coming soon!
The empty comments next to HandleFuncs on main.go are there to remind me about which routes I've added to the router generator route list.
Fixed the Modlogs Page so that you can view it without the ManageThemes permissions. I accidentally used the wrong permission there before.
Changed the router algorithm to align better with the upcoming generated router. It's faster too.
This commit is contained in:
Azareal 2017-04-12 11:10:36 +01:00
parent a906f17470
commit d7cf48e43d
15 changed files with 386 additions and 173 deletions

4
.gitignore vendored
View File

@ -2,8 +2,6 @@ tmp/*
tmp2/* tmp2/*
uploads/avatar_* uploads/avatar_*
bin/* bin/*
gosora.exe *.exe
gosora.test.exe
install.exe
*.prof *.prof
.DS_Store .DS_Store

View File

@ -217,6 +217,7 @@ ManageForums
EditSettings EditSettings
ManageThemes ManageThemes
ManagePlugins ManagePlugins
ViewAdminLogs
ViewIPs ViewIPs
ViewTopic ViewTopic
@ -231,7 +232,7 @@ PinTopic
CloseTopic CloseTopic
*/ */
INSERT INTO users_groups(`name`,`permissions`,`is_mod`,`is_admin`,`tag`) VALUES ('Administrator','{"BanUsers":true,"ActivateUsers":true,"EditUser":true,"EditUserEmail":true,"EditUserPassword":true,"EditUserGroup":true,"EditUserGroupSuperMod":true,"EditUserGroupAdmin":false,"EditGroup":true,"EditGroupLocalPerms":true,"EditGroupGlobalPerms":true,"EditGroupSuperMod":true,"EditGroupAdmin":false,"ManageForums":true,"EditSettings":true,"ManageThemes":true,"ManagePlugins":true,"ViewIPs":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true}',1,1,"Admin"); INSERT INTO users_groups(`name`,`permissions`,`is_mod`,`is_admin`,`tag`) VALUES ('Administrator','{"BanUsers":true,"ActivateUsers":true,"EditUser":true,"EditUserEmail":true,"EditUserPassword":true,"EditUserGroup":true,"EditUserGroupSuperMod":true,"EditUserGroupAdmin":false,"EditGroup":true,"EditGroupLocalPerms":true,"EditGroupGlobalPerms":true,"EditGroupSuperMod":true,"EditGroupAdmin":false,"ManageForums":true,"EditSettings":true,"ManageThemes":true,"ManagePlugins":true,"ViewAdminLogs":true,"ViewIPs":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true}',1,1,"Admin");
INSERT INTO users_groups(`name`,`permissions`,`is_mod`,`tag`) VALUES ('Moderator','{"BanUsers":true,"ActivateUsers":false,"EditUser":true,"EditUserEmail":false,"EditUserGroup":true,"ViewIPs":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true}',1,"Mod"); INSERT INTO users_groups(`name`,`permissions`,`is_mod`,`tag`) VALUES ('Moderator','{"BanUsers":true,"ActivateUsers":false,"EditUser":true,"EditUserEmail":false,"EditUserGroup":true,"ViewIPs":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true}',1,"Mod");
INSERT INTO users_groups(`name`,`permissions`) VALUES ('Member','{"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"CreateReply":true}'); INSERT INTO users_groups(`name`,`permissions`) VALUES ('Member','{"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"CreateReply":true}');
INSERT INTO users_groups(`name`,`permissions`,`is_banned`) VALUES ('Banned','{"ViewTopic":true}',1); INSERT INTO users_groups(`name`,`permissions`,`is_banned`) VALUES ('Banned','{"ViewTopic":true}',1);

View File

@ -3,6 +3,7 @@ import "os"
import "fmt" import "fmt"
import "log" import "log"
import "bytes" import "bytes"
import "strings"
import "strconv" import "strconv"
import "math/rand" import "math/rand"
import "testing" import "testing"
@ -10,17 +11,17 @@ import "net/http"
import "net/http/httptest" import "net/http/httptest"
import "io/ioutil" import "io/ioutil"
import "database/sql" import "database/sql"
import "runtime/pprof"
//import _ "github.com/go-sql-driver/mysql" //import _ "github.com/go-sql-driver/mysql"
//import "github.com/erikstmartin/go-testdb" //import "github.com/erikstmartin/go-testdb"
//import "github.com/husobee/vestigo" //import "github.com/husobee/vestigo"
import "runtime/pprof"
var db_test *sql.DB var db_test *sql.DB
var db_prod *sql.DB var db_prod *sql.DB
var gloinited bool = false var gloinited bool = false
func gloinit() { func gloinit() {
var err error
debug = false debug = false
nogrouplog = true nogrouplog = true
@ -29,7 +30,11 @@ func gloinit() {
//log.SetOutput(discard) //log.SetOutput(discard)
init_themes() init_themes()
init_database(err) err := init_database()
if err != nil {
log.Fatal(err)
}
db_prod = db db_prod = db
//db_test, err = sql.Open("testdb","") //db_test, err = sql.Open("testdb","")
//if err != nil { //if err != nil {
@ -73,16 +78,16 @@ func BenchmarkTopicTemplateSerial(b *testing.B) {
topic := TopicUser{Title: "Lol",Content: "Hey everyone!",CreatedBy: 1,CreatedAt: "0000-00-00 00:00:00",ParentID: 1,CreatedByName:"Admin",Css: no_css_tmpl,Tag: "Admin", Level: 58, IpAddress: "127.0.0.1"} topic := TopicUser{Title: "Lol",Content: "Hey everyone!",CreatedBy: 1,CreatedAt: "0000-00-00 00:00:00",ParentID: 1,CreatedByName:"Admin",Css: no_css_tmpl,Tag: "Admin", Level: 58, IpAddress: "127.0.0.1"}
var replyList []Reply var replyList []Reply
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1}) replyList = append(replyList, Reply{0,0,"Hey everyone!","Hey everyone!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
tpage := TopicPage{"Topic Blah",user,noticeList,replyList,topic,1,1,false} tpage := TopicPage{"Topic Blah",user,noticeList,replyList,topic,1,1,false}
tpage2 := TopicPage{"Topic Blah",admin,noticeList,replyList,topic,1,1,false} tpage2 := TopicPage{"Topic Blah",admin,noticeList,replyList,topic,1,1,false}
@ -1410,3 +1415,32 @@ func TestForumGuestRoute(t *testing.T) {
/*func TestRoute(t *testing.T) { /*func TestRoute(t *testing.T) {
}*/ }*/
func TestSplittyThing(t *testing.T) {
fmt.Println("Splitty thing test")
var extra_data string
var path string = "/pages/hohoho"
fmt.Println("Raw Path:",path)
if path[len(path) - 1] != '/' {
extra_data = path[strings.LastIndexByte(path,'/') + 1:]
path = path[:strings.LastIndexByte(path,'/') + 1]
}
fmt.Println("Path:", path)
fmt.Println("Extra Data:", extra_data)
fmt.Println("Path Bytes:", []byte(path))
fmt.Println("Extra Data Bytes:", []byte(extra_data))
fmt.Println("Splitty thing test")
path = "/topics/"
extra_data = ""
fmt.Println("Raw Path:",path)
if path[len(path) - 1] != '/' {
extra_data = path[strings.LastIndexByte(path,'/') + 1:]
path = path[:strings.LastIndexByte(path,'/') + 1]
}
fmt.Println("Path:", path)
fmt.Println("Extra Data:", extra_data)
fmt.Println("Path Bytes:", []byte(path))
fmt.Println("Extra Data Bytes:", []byte(extra_data))
}

17
main.go
View File

@ -19,7 +19,7 @@ const day int = hour * 24
const month int = day * 30 const month int = day * 30
const year int = day * 365 const year int = day * 365
const kilobyte int = 1024 const kilobyte int = 1024
const megabyte int = 1024 * 1024 const megabyte int = kilobyte * 1024
const saltLength int = 32 const saltLength int = 32
const sessionLength int = 80 const sessionLength int = 80
var nogrouplog bool = false // This is mainly for benchmarks, as we don't want a lot of information getting in the way of the results var nogrouplog bool = false // This is mainly for benchmarks, as we don't want a lot of information getting in the way of the results
@ -158,8 +158,11 @@ func main(){
//} //}
init_themes() init_themes()
var err error err := init_database()
init_database(err) if err != nil {
log.Fatal(err)
}
init_templates() init_templates()
db.SetMaxOpenConns(64) db.SetMaxOpenConns(64)
@ -184,13 +187,13 @@ func main(){
init_plugins() init_plugins()
router := NewRouter() router := NewRouter()
router.HandleFunc("/static/", route_static) router.HandleFunc("/static/", route_static)//
fs_u := http.FileServer(http.Dir("./uploads")) fs_u := http.FileServer(http.Dir("./uploads"))
router.Handle("/uploads/", http.StripPrefix("/uploads/",fs_u)) router.Handle("/uploads/", http.StripPrefix("/uploads/",fs_u))//
router.HandleFunc("/overview/", route_overview) router.HandleFunc("/overview/", route_overview)//
router.HandleFunc("/topics/create/", route_topic_create) router.HandleFunc("/topics/create/", route_topic_create)
router.HandleFunc("/topics/", route_topics) router.HandleFunc("/topics/", route_topics)//
router.HandleFunc("/forums/", route_forums) router.HandleFunc("/forums/", route_forums)
router.HandleFunc("/forum/", route_forum) router.HandleFunc("/forum/", route_forum)
router.HandleFunc("/topic/create/submit/", route_create_topic) router.HandleFunc("/topic/create/submit/", route_create_topic)

216
mysql.go
View File

@ -10,6 +10,7 @@ import "encoding/json"
var db *sql.DB var db *sql.DB
var db_version string var db_version string
var db_collation string = "utf8mb4_general_ci"
var get_user_stmt *sql.Stmt var get_user_stmt *sql.Stmt
var get_full_user_stmt *sql.Stmt var get_full_user_stmt *sql.Stmt
@ -94,19 +95,19 @@ var update_theme_stmt *sql.Stmt
var add_modlog_entry_stmt *sql.Stmt var add_modlog_entry_stmt *sql.Stmt
var add_adminlog_entry_stmt *sql.Stmt var add_adminlog_entry_stmt *sql.Stmt
func init_database(err error) { func init_database() (err error) {
if(dbpassword != ""){ if(dbpassword != ""){
dbpassword = ":" + dbpassword dbpassword = ":" + dbpassword
} }
db, err = sql.Open("mysql",dbuser + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + dbname + "?collation=utf8mb4_general_ci") db, err = sql.Open("mysql",dbuser + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + dbname + "?collation=" + db_collation)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
// Make sure that the connection is alive.. // Make sure that the connection is alive..
err = db.Ping() err = db.Ping()
if err != nil { if err != nil {
log.Fatal(err) return err
} }
// Getting the database version.. // Getting the database version..
@ -115,259 +116,259 @@ func init_database(err error) {
/*log.Print("Preparing get_session statement.") /*log.Print("Preparing get_session statement.")
get_session_stmt, err = db.Prepare("select `uid`,`name`,`group`,`is_super_admin`,`session`,`email`,`avatar`,`message`,`url_prefix`,`url_name`,`level`,`score`,`last_ip` from `users` where `uid` = ? and `session` = ? AND `session` <> ''") get_session_stmt, err = db.Prepare("select `uid`,`name`,`group`,`is_super_admin`,`session`,`email`,`avatar`,`message`,`url_prefix`,`url_name`,`level`,`score`,`last_ip` from `users` where `uid` = ? and `session` = ? AND `session` <> ''")
if err != nil { if err != nil {
log.Fatal(err) return err
}*/ }*/
log.Print("Preparing get_user statement.") log.Print("Preparing get_user statement.")
get_user_stmt, err = db.Prepare("select `name`,`group`,`is_super_admin`,`avatar`,`message`,`url_prefix`,`url_name`,`level` from `users` where `uid` = ?") get_user_stmt, err = db.Prepare("select `name`,`group`,`is_super_admin`,`avatar`,`message`,`url_prefix`,`url_name`,`level` from `users` where `uid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_full_user statement.") log.Print("Preparing get_full_user statement.")
get_full_user_stmt, err = db.Prepare("select `name`,`group`,`is_super_admin`,`session`,`email`,`avatar`,`message`,`url_prefix`,`url_name`,`level`,`score`,`last_ip` from `users` where `uid` = ?") get_full_user_stmt, err = db.Prepare("select `name`,`group`,`is_super_admin`,`session`,`email`,`avatar`,`message`,`url_prefix`,`url_name`,`level`,`score`,`last_ip` from `users` where `uid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_topic_list statement.") log.Print("Preparing get_topic_list statement.")
get_topic_list_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC") get_topic_list_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_topic_user statement.") log.Print("Preparing get_topic_user statement.")
get_topic_user_stmt, err = db.Prepare("select topics.title, topics.content, topics.createdBy, topics.createdAt, topics.is_closed, topics.sticky, topics.parentID, topics.ipaddress, topics.postCount, topics.likeCount, users.name, users.avatar, users.group, users.url_prefix, users.url_name, users.level from topics left join users ON topics.createdBy = users.uid where tid = ?") get_topic_user_stmt, err = db.Prepare("select topics.title, topics.content, topics.createdBy, topics.createdAt, topics.is_closed, topics.sticky, topics.parentID, topics.ipaddress, topics.postCount, topics.likeCount, users.name, users.avatar, users.group, users.url_prefix, users.url_name, users.level from topics left join users ON topics.createdBy = users.uid where tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_topic statement.") log.Print("Preparing get_topic statement.")
get_topic_stmt, err = db.Prepare("select title, content, createdBy, createdAt, is_closed, sticky, parentID, ipaddress, postCount, likeCount from topics where tid = ?") get_topic_stmt, err = db.Prepare("select title, content, createdBy, createdAt, is_closed, sticky, parentID, ipaddress, postCount, likeCount from topics where tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_topic_by_reply statement.") log.Print("Preparing get_topic_by_reply statement.")
get_topic_by_reply_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.createdAt, topics.is_closed, topics.sticky, topics.parentID, topics.ipaddress, topics.postCount, topics.likeCount from replies left join topics on replies.tid = topics.tid where rid = ?") get_topic_by_reply_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.createdAt, topics.is_closed, topics.sticky, topics.parentID, topics.ipaddress, topics.postCount, topics.likeCount from replies left join topics on replies.tid = topics.tid where rid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_topic_replies statement.") log.Print("Preparing get_topic_replies statement.")
get_topic_replies_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress from replies left join users ON replies.createdBy = users.uid where tid = ?") get_topic_replies_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress from replies left join users ON replies.createdBy = users.uid where tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_topic_replies_offset statement.") log.Print("Preparing get_topic_replies_offset statement.")
get_topic_replies_offset_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress, replies.likeCount, replies.actionType from replies left join users on replies.createdBy = users.uid where tid = ? limit ?, " + strconv.Itoa(items_per_page)) get_topic_replies_offset_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress, replies.likeCount, replies.actionType from replies left join users on replies.createdBy = users.uid where tid = ? limit ?, " + strconv.Itoa(items_per_page))
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_reply statement.") log.Print("Preparing get_reply statement.")
get_reply_stmt, err = db.Prepare("select content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress, likeCount from replies where rid = ?") get_reply_stmt, err = db.Prepare("select content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress, likeCount from replies where rid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_forum_topics statement.") log.Print("Preparing get_forum_topics statement.")
get_forum_topics_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid where topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy desc") get_forum_topics_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid where topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy desc")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_forum_topics_offset statement.") log.Print("Preparing get_forum_topics_offset statement.")
get_forum_topics_offset_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, topics.likeCount, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid WHERE topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC limit ?, " + strconv.Itoa(items_per_page)) get_forum_topics_offset_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, topics.likeCount, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid WHERE topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC limit ?, " + strconv.Itoa(items_per_page))
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_topic statement.") log.Print("Preparing create_topic statement.")
create_topic_stmt, err = db.Prepare("insert into topics(parentID,title,content,parsed_content,createdAt,lastReplyAt,ipaddress,words,createdBy) VALUES(?,?,?,?,NOW(),NOW(),?,?,?)") create_topic_stmt, err = db.Prepare("insert into topics(parentID,title,content,parsed_content,createdAt,lastReplyAt,ipaddress,words,createdBy) VALUES(?,?,?,?,NOW(),NOW(),?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_report statement.") log.Print("Preparing create_report statement.")
create_report_stmt, err = db.Prepare("INSERT INTO topics(title,content,parsed_content,createdAt,lastReplyAt,createdBy,data,parentID) VALUES(?,?,?,NOW(),NOW(),?,?,1)") create_report_stmt, err = db.Prepare("INSERT INTO topics(title,content,parsed_content,createdAt,lastReplyAt,createdBy,data,parentID) VALUES(?,?,?,NOW(),NOW(),?,?,1)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_reply statement.") log.Print("Preparing create_reply statement.")
create_reply_stmt, err = db.Prepare("INSERT INTO replies(tid,content,parsed_content,createdAt,ipaddress,words,createdBy) VALUES(?,?,?,NOW(),?,?,?)") create_reply_stmt, err = db.Prepare("INSERT INTO replies(tid,content,parsed_content,createdAt,ipaddress,words,createdBy) VALUES(?,?,?,NOW(),?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_action_reply statement.") log.Print("Preparing create_action_reply statement.")
create_action_reply_stmt, err = db.Prepare("INSERT INTO replies(tid,actionType,ipaddress,createdBy) VALUES(?,?,?,?)") create_action_reply_stmt, err = db.Prepare("INSERT INTO replies(tid,actionType,ipaddress,createdBy) VALUES(?,?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_replies_to_topic statement.") log.Print("Preparing add_replies_to_topic statement.")
add_replies_to_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount + ?, lastReplyAt = NOW() WHERE tid = ?") add_replies_to_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount + ?, lastReplyAt = NOW() WHERE tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing remove_replies_from_topic statement.") log.Print("Preparing remove_replies_from_topic statement.")
remove_replies_from_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount - ? WHERE tid = ?") remove_replies_from_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount - ? WHERE tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_topics_to_forum statement.") log.Print("Preparing add_topics_to_forum statement.")
add_topics_to_forum_stmt, err = db.Prepare("UPDATE forums SET topicCount = topicCount + ? WHERE fid = ?") add_topics_to_forum_stmt, err = db.Prepare("UPDATE forums SET topicCount = topicCount + ? WHERE fid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing remove_topics_from_forum statement.") log.Print("Preparing remove_topics_from_forum statement.")
remove_topics_from_forum_stmt, err = db.Prepare("UPDATE forums SET topicCount = topicCount - ? WHERE fid = ?") remove_topics_from_forum_stmt, err = db.Prepare("UPDATE forums SET topicCount = topicCount - ? WHERE fid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_forum_cache statement.") log.Print("Preparing update_forum_cache statement.")
update_forum_cache_stmt, err = db.Prepare("UPDATE forums SET lastTopic = ?, lastTopicID = ?, lastReplyer = ?, lastReplyerID = ?, lastTopicTime = NOW() WHERE fid = ?") update_forum_cache_stmt, err = db.Prepare("UPDATE forums SET lastTopic = ?, lastTopicID = ?, lastReplyer = ?, lastReplyerID = ?, lastTopicTime = NOW() WHERE fid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_like statement.") log.Print("Preparing create_like statement.")
create_like_stmt, err = db.Prepare("INSERT INTO likes(weight, targetItem, targetType, sentBy) VALUES(?,?,?,?)") create_like_stmt, err = db.Prepare("INSERT INTO likes(weight, targetItem, targetType, sentBy) VALUES(?,?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_likes_to_topic statement.") log.Print("Preparing add_likes_to_topic statement.")
add_likes_to_topic_stmt, err = db.Prepare("UPDATE topics SET likeCount = likeCount + ? WHERE tid = ?") add_likes_to_topic_stmt, err = db.Prepare("UPDATE topics SET likeCount = likeCount + ? WHERE tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_likes_to_reply statement.") log.Print("Preparing add_likes_to_reply statement.")
add_likes_to_reply_stmt, err = db.Prepare("UPDATE replies SET likeCount = likeCount + ? WHERE rid = ?") add_likes_to_reply_stmt, err = db.Prepare("UPDATE replies SET likeCount = likeCount + ? WHERE rid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_activity statement.") log.Print("Preparing add_activity statement.")
add_activity_stmt, err = db.Prepare("INSERT INTO activity_stream(actor,targetUser,event,elementType,elementID) VALUES(?,?,?,?,?)") add_activity_stmt, err = db.Prepare("INSERT INTO activity_stream(actor,targetUser,event,elementType,elementID) VALUES(?,?,?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing notify_watchers statement.") log.Print("Preparing notify_watchers statement.")
notify_watchers_stmt, err = db.Prepare("INSERT INTO activity_stream_matches(watcher, asid) SELECT activity_subscriptions.user, activity_stream.asid FROM activity_stream INNER JOIN activity_subscriptions ON activity_subscriptions.targetType = activity_stream.elementType and activity_subscriptions.targetID = activity_stream.elementID and activity_subscriptions.user != activity_stream.actor where asid = ?") notify_watchers_stmt, err = db.Prepare("INSERT INTO activity_stream_matches(watcher, asid) SELECT activity_subscriptions.user, activity_stream.asid FROM activity_stream INNER JOIN activity_subscriptions ON activity_subscriptions.targetType = activity_stream.elementType and activity_subscriptions.targetID = activity_stream.elementID and activity_subscriptions.user != activity_stream.actor where asid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing notify_one statement.") log.Print("Preparing notify_one statement.")
notify_one_stmt, err = db.Prepare("INSERT INTO activity_stream_matches(watcher,asid) VALUES(?,?)") notify_one_stmt, err = db.Prepare("INSERT INTO activity_stream_matches(watcher,asid) VALUES(?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_subscription statement.") log.Print("Preparing add_subscription statement.")
add_subscription_stmt, err = db.Prepare("INSERT INTO activity_subscriptions(user,targetID,targetType,level) VALUES(?,?,?,2)") add_subscription_stmt, err = db.Prepare("INSERT INTO activity_subscriptions(user,targetID,targetType,level) VALUES(?,?,?,2)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing edit_topic statement.") log.Print("Preparing edit_topic statement.")
edit_topic_stmt, err = db.Prepare("UPDATE topics SET title = ?, content = ?, parsed_content = ?, is_closed = ? WHERE tid = ?") edit_topic_stmt, err = db.Prepare("UPDATE topics SET title = ?, content = ?, parsed_content = ?, is_closed = ? WHERE tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing edit_reply statement.") log.Print("Preparing edit_reply statement.")
edit_reply_stmt, err = db.Prepare("UPDATE replies SET content = ?, parsed_content = ? WHERE rid = ?") edit_reply_stmt, err = db.Prepare("UPDATE replies SET content = ?, parsed_content = ? WHERE rid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing delete_reply statement.") log.Print("Preparing delete_reply statement.")
delete_reply_stmt, err = db.Prepare("DELETE FROM replies WHERE rid = ?") delete_reply_stmt, err = db.Prepare("DELETE FROM replies WHERE rid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing delete_topic statement.") log.Print("Preparing delete_topic statement.")
delete_topic_stmt, err = db.Prepare("DELETE FROM topics WHERE tid = ?") delete_topic_stmt, err = db.Prepare("DELETE FROM topics WHERE tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing stick_topic statement.") log.Print("Preparing stick_topic statement.")
stick_topic_stmt, err = db.Prepare("UPDATE topics SET sticky = 1 WHERE tid = ?") stick_topic_stmt, err = db.Prepare("UPDATE topics SET sticky = 1 WHERE tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing unstick_topic statement.") log.Print("Preparing unstick_topic statement.")
unstick_topic_stmt, err = db.Prepare("UPDATE topics SET sticky = 0 WHERE tid = ?") unstick_topic_stmt, err = db.Prepare("UPDATE topics SET sticky = 0 WHERE tid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_activity_feed_by_watcher statement.") log.Print("Preparing get_activity_feed_by_watcher statement.")
get_activity_feed_by_watcher_stmt, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ?") get_activity_feed_by_watcher_stmt, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_last_ip statement.") log.Print("Preparing update_last_ip statement.")
update_last_ip_stmt, err = db.Prepare("UPDATE users SET last_ip = ? WHERE uid = ?") update_last_ip_stmt, err = db.Prepare("UPDATE users SET last_ip = ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing login statement.") log.Print("Preparing login statement.")
login_stmt, err = db.Prepare("SELECT `uid`,`name`,`password`,`salt` FROM `users` WHERE `name` = ?") login_stmt, err = db.Prepare("SELECT `uid`,`name`,`password`,`salt` FROM `users` WHERE `name` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_session statement.") log.Print("Preparing update_session statement.")
update_session_stmt, err = db.Prepare("UPDATE users SET session = ? WHERE uid = ?") update_session_stmt, err = db.Prepare("UPDATE users SET session = ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing logout statement.") log.Print("Preparing logout statement.")
logout_stmt, err = db.Prepare("UPDATE users SET session = '' WHERE uid = ?") logout_stmt, err = db.Prepare("UPDATE users SET session = '' WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing set_password statement.") log.Print("Preparing set_password statement.")
set_password_stmt, err = db.Prepare("UPDATE users SET password = ?, salt = ? WHERE uid = ?") set_password_stmt, err = db.Prepare("UPDATE users SET password = ?, salt = ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing get_password statement.") log.Print("Preparing get_password statement.")
get_password_stmt, err = db.Prepare("SELECT `password`,`salt` FROM `users` WHERE `uid` = ?") get_password_stmt, err = db.Prepare("SELECT `password`,`salt` FROM `users` WHERE `uid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing set_avatar statement.") log.Print("Preparing set_avatar statement.")
set_avatar_stmt, err = db.Prepare("UPDATE users SET avatar = ? WHERE uid = ?") set_avatar_stmt, err = db.Prepare("UPDATE users SET avatar = ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing set_username statement.") log.Print("Preparing set_username statement.")
set_username_stmt, err = db.Prepare("UPDATE users SET name = ? WHERE uid = ?") set_username_stmt, err = db.Prepare("UPDATE users SET name = ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
// Add an admin version of register_stmt with more flexibility // Add an admin version of register_stmt with more flexibility
@ -376,236 +377,236 @@ func init_database(err error) {
log.Print("Preparing register statement.") log.Print("Preparing register statement.")
register_stmt, err = db.Prepare("INSERT INTO users(`name`,`email`,`password`,`salt`,`group`,`is_super_admin`,`session`,`active`,`message`) VALUES(?,?,?,?,?,0,?,?,'')") register_stmt, err = db.Prepare("INSERT INTO users(`name`,`email`,`password`,`salt`,`group`,`is_super_admin`,`session`,`active`,`message`) VALUES(?,?,?,?,?,0,?,?,'')")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing username_exists statement.") log.Print("Preparing username_exists statement.")
username_exists_stmt, err = db.Prepare("SELECT `name` FROM `users` WHERE `name` = ?") username_exists_stmt, err = db.Prepare("SELECT `name` FROM `users` WHERE `name` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing change_group statement.") log.Print("Preparing change_group statement.")
change_group_stmt, err = db.Prepare("update `users` set `group` = ? where `uid` = ?") change_group_stmt, err = db.Prepare("update `users` set `group` = ? where `uid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_email statement.") log.Print("Preparing add_email statement.")
add_email_stmt, err = db.Prepare("INSERT INTO emails(`email`,`uid`,`validated`,`token`) VALUES(?,?,?,?)") add_email_stmt, err = db.Prepare("INSERT INTO emails(`email`,`uid`,`validated`,`token`) VALUES(?,?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_email statement.") log.Print("Preparing update_email statement.")
update_email_stmt, err = db.Prepare("UPDATE emails SET email = ?, uid = ?, validated = ?, token = ? WHERE email = ?") update_email_stmt, err = db.Prepare("UPDATE emails SET email = ?, uid = ?, validated = ?, token = ? WHERE email = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing verify_email statement.") log.Print("Preparing verify_email statement.")
verify_email_stmt, err = db.Prepare("UPDATE emails SET validated = 1, token = '' WHERE email = ?") verify_email_stmt, err = db.Prepare("UPDATE emails SET validated = 1, token = '' WHERE email = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing activate_user statement.") log.Print("Preparing activate_user statement.")
activate_user_stmt, err = db.Prepare("UPDATE users SET active = 1 WHERE uid = ?") activate_user_stmt, err = db.Prepare("UPDATE users SET active = 1 WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_user_level statement.") log.Print("Preparing update_user_level statement.")
update_user_level_stmt, err = db.Prepare("UPDATE users SET level = ? WHERE uid = ?") update_user_level_stmt, err = db.Prepare("UPDATE users SET level = ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing increment_user_score statement.") log.Print("Preparing increment_user_score statement.")
increment_user_score_stmt, err = db.Prepare("UPDATE users SET score = score + ? WHERE uid = ?") increment_user_score_stmt, err = db.Prepare("UPDATE users SET score = score + ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing increment_user_posts statement.") log.Print("Preparing increment_user_posts statement.")
increment_user_posts_stmt, err = db.Prepare("UPDATE users SET posts = posts + ? WHERE uid = ?") increment_user_posts_stmt, err = db.Prepare("UPDATE users SET posts = posts + ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing increment_user_bigposts statement.") log.Print("Preparing increment_user_bigposts statement.")
increment_user_bigposts_stmt, err = db.Prepare("UPDATE users SET posts = posts + ?, bigposts = bigposts + ? WHERE uid = ?") increment_user_bigposts_stmt, err = db.Prepare("UPDATE users SET posts = posts + ?, bigposts = bigposts + ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing increment_user_megaposts statement.") log.Print("Preparing increment_user_megaposts statement.")
increment_user_megaposts_stmt, err = db.Prepare("UPDATE users SET posts = posts + ?, bigposts = bigposts + ?, megaposts = megaposts + ? WHERE uid = ?") increment_user_megaposts_stmt, err = db.Prepare("UPDATE users SET posts = posts + ?, bigposts = bigposts + ?, megaposts = megaposts + ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing increment_user_topics statement.") log.Print("Preparing increment_user_topics statement.")
increment_user_topics_stmt, err = db.Prepare("UPDATE users SET topics = topics + ? WHERE uid = ?") increment_user_topics_stmt, err = db.Prepare("UPDATE users SET topics = topics + ? WHERE uid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_profile_reply statement.") log.Print("Preparing create_profile_reply statement.")
create_profile_reply_stmt, err = db.Prepare("INSERT INTO users_replies(uid,content,parsed_content,createdAt,createdBy) VALUES(?,?,?,NOW(),?)") create_profile_reply_stmt, err = db.Prepare("INSERT INTO users_replies(uid,content,parsed_content,createdAt,createdBy) VALUES(?,?,?,NOW(),?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing edit_profile_reply statement.") log.Print("Preparing edit_profile_reply statement.")
edit_profile_reply_stmt, err = db.Prepare("UPDATE users_replies SET content = ?, parsed_content = ? WHERE rid = ?") edit_profile_reply_stmt, err = db.Prepare("UPDATE users_replies SET content = ?, parsed_content = ? WHERE rid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing delete_profile_reply statement.") log.Print("Preparing delete_profile_reply statement.")
delete_profile_reply_stmt, err = db.Prepare("DELETE FROM users_replies WHERE rid = ?") delete_profile_reply_stmt, err = db.Prepare("DELETE FROM users_replies WHERE rid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_forum statement.") log.Print("Preparing create_forum statement.")
create_forum_stmt, err = db.Prepare("INSERT INTO forums(name,active,preset) VALUES(?,?,?)") create_forum_stmt, err = db.Prepare("INSERT INTO forums(name,active,preset) VALUES(?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing delete_forum statement.") log.Print("Preparing delete_forum statement.")
//delete_forum_stmt, err = db.Prepare("DELETE FROM forums WHERE fid = ?") //delete_forum_stmt, err = db.Prepare("DELETE FROM forums WHERE fid = ?")
delete_forum_stmt, err = db.Prepare("update forums set name= '', active = 0 where fid = ?") delete_forum_stmt, err = db.Prepare("update forums set name= '', active = 0 where fid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_forum statement.") log.Print("Preparing update_forum statement.")
update_forum_stmt, err = db.Prepare("update forums set name = ?, active = ?, preset = ? where fid = ?") update_forum_stmt, err = db.Prepare("update forums set name = ?, active = ?, preset = ? where fid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing forum_entry_exists statement.") log.Print("Preparing forum_entry_exists statement.")
forum_entry_exists_stmt, err = db.Prepare("SELECT `fid` FROM `forums` WHERE `name` = '' order by fid asc limit 1") forum_entry_exists_stmt, err = db.Prepare("SELECT `fid` FROM `forums` WHERE `name` = '' order by fid asc limit 1")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing group_entry_exists statement.") log.Print("Preparing group_entry_exists statement.")
group_entry_exists_stmt, err = db.Prepare("SELECT `gid` FROM `users_groups` WHERE `name` = '' order by gid asc limit 1") group_entry_exists_stmt, err = db.Prepare("SELECT `gid` FROM `users_groups` WHERE `name` = '' order by gid asc limit 1")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing delete_forum_perms_by_forum statement.") log.Print("Preparing delete_forum_perms_by_forum statement.")
delete_forum_perms_by_forum_stmt, err = db.Prepare("DELETE FROM forums_permissions WHERE fid = ?") delete_forum_perms_by_forum_stmt, err = db.Prepare("DELETE FROM forums_permissions WHERE fid = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_forum_perms_to_forum statement.") log.Print("Preparing add_forum_perms_to_forum statement.")
add_forum_perms_to_forum_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) VALUES(?,?,?,?)") add_forum_perms_to_forum_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) VALUES(?,?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_forum_perms_to_forum_admins statement.") log.Print("Preparing add_forum_perms_to_forum_admins statement.")
add_forum_perms_to_forum_admins_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) SELECT `gid`,? AS fid,? AS preset,? AS permissions FROM users_groups WHERE is_admin = 1") add_forum_perms_to_forum_admins_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) SELECT `gid`,? AS fid,? AS preset,? AS permissions FROM users_groups WHERE is_admin = 1")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_forum_perms_to_forum_staff statement.") log.Print("Preparing add_forum_perms_to_forum_staff statement.")
add_forum_perms_to_forum_staff_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) SELECT `gid`,? AS fid,? AS preset,? AS permissions FROM users_groups WHERE is_admin = 0 AND is_mod = 1") add_forum_perms_to_forum_staff_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) SELECT `gid`,? AS fid,? AS preset,? AS permissions FROM users_groups WHERE is_admin = 0 AND is_mod = 1")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_forum_perms_to_forum_members statement.") log.Print("Preparing add_forum_perms_to_forum_members statement.")
add_forum_perms_to_forum_members_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) SELECT `gid`,? AS fid,? AS preset,? AS permissions FROM users_groups WHERE is_admin = 0 AND is_mod = 0 AND is_banned = 0") add_forum_perms_to_forum_members_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) SELECT `gid`,? AS fid,? AS preset,? AS permissions FROM users_groups WHERE is_admin = 0 AND is_mod = 0 AND is_banned = 0")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_forum_perms_to_group statement.") log.Print("Preparing add_forum_perms_to_group statement.")
add_forum_perms_to_group_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) VALUES(?,?,?,?)") add_forum_perms_to_group_stmt, err = db.Prepare("INSERT INTO forums_permissions(gid,fid,preset,permissions) VALUES(?,?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_setting statement.") log.Print("Preparing update_setting statement.")
update_setting_stmt, err = db.Prepare("UPDATE settings SET content = ? WHERE name = ?") update_setting_stmt, err = db.Prepare("UPDATE settings SET content = ? WHERE name = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_plugin statement.") log.Print("Preparing add_plugin statement.")
add_plugin_stmt, err = db.Prepare("INSERT INTO plugins(uname,active) VALUES(?,?)") add_plugin_stmt, err = db.Prepare("INSERT INTO plugins(uname,active) VALUES(?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_plugin statement.") log.Print("Preparing update_plugin statement.")
update_plugin_stmt, err = db.Prepare("UPDATE plugins SET active = ? WHERE uname = ?") update_plugin_stmt, err = db.Prepare("UPDATE plugins SET active = ? WHERE uname = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_theme statement.") log.Print("Preparing add_theme statement.")
add_theme_stmt, err = db.Prepare("INSERT INTO `themes`(`uname`,`default`) VALUES(?,?)") add_theme_stmt, err = db.Prepare("INSERT INTO `themes`(`uname`,`default`) VALUES(?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_theme statement.") log.Print("Preparing update_theme statement.")
update_theme_stmt, err = db.Prepare("update `themes` set `default` = ? where `uname` = ?") update_theme_stmt, err = db.Prepare("update `themes` set `default` = ? where `uname` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_user statement.") log.Print("Preparing update_user statement.")
update_user_stmt, err = db.Prepare("update `users` set `name` = ?,`email` = ?,`group` = ? where `uid` = ?") update_user_stmt, err = db.Prepare("update `users` set `name` = ?,`email` = ?,`group` = ? where `uid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_group_rank statement.") log.Print("Preparing update_group_rank statement.")
update_group_perms_stmt, err = db.Prepare("update `users_groups` set `permissions` = ? where `gid` = ?") update_group_perms_stmt, err = db.Prepare("update `users_groups` set `permissions` = ? where `gid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_group_rank statement.") log.Print("Preparing update_group_rank statement.")
update_group_rank_stmt, err = db.Prepare("update `users_groups` set `is_admin` = ?, `is_mod` = ?, `is_banned` = ? where `gid` = ?") update_group_rank_stmt, err = db.Prepare("update `users_groups` set `is_admin` = ?, `is_mod` = ?, `is_banned` = ? where `gid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing update_group statement.") log.Print("Preparing update_group statement.")
update_group_stmt, err = db.Prepare("update `users_groups` set `name` = ?, `tag` = ? where `gid` = ?") update_group_stmt, err = db.Prepare("update `users_groups` set `name` = ?, `tag` = ? where `gid` = ?")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing create_group statement.") log.Print("Preparing create_group statement.")
create_group_stmt, err = db.Prepare("INSERT INTO users_groups(name,tag,is_admin,is_mod,is_banned,permissions) VALUES(?,?,?,?,?,?)") create_group_stmt, err = db.Prepare("INSERT INTO users_groups(name,tag,is_admin,is_mod,is_banned,permissions) VALUES(?,?,?,?,?,?)")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_modlog_entry statement.") log.Print("Preparing add_modlog_entry statement.")
add_modlog_entry_stmt, err = db.Prepare("INSERT INTO moderation_logs(action,elementID,elementType,ipaddress,actorID,doneAt) VALUES(?,?,?,?,?,NOW())") add_modlog_entry_stmt, err = db.Prepare("INSERT INTO moderation_logs(action,elementID,elementType,ipaddress,actorID,doneAt) VALUES(?,?,?,?,?,NOW())")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Preparing add_adminlog_entry statement.") log.Print("Preparing add_adminlog_entry statement.")
add_adminlog_entry_stmt, err = db.Prepare("INSERT INTO moderation_logs(action,elementID,elementType,ipaddress,actorID,doneAt) VALUES(?,?,?,?,?,NOW())") add_adminlog_entry_stmt, err = db.Prepare("INSERT INTO moderation_logs(action,elementID,elementType,ipaddress,actorID,doneAt) VALUES(?,?,?,?,?,NOW())")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Loading the usergroups.") log.Print("Loading the usergroups.")
@ -613,7 +614,7 @@ func init_database(err error) {
rows, err := db.Query("select gid,name,permissions,is_mod,is_admin,is_banned,tag from users_groups") rows, err := db.Query("select gid,name,permissions,is_mod,is_admin,is_banned,tag from users_groups")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer rows.Close() defer rows.Close()
@ -622,7 +623,7 @@ func init_database(err error) {
group := Group{ID: 0,} group := Group{ID: 0,}
err := rows.Scan(&group.ID, &group.Name, &group.PermissionsText, &group.Is_Mod, &group.Is_Admin, &group.Is_Banned, &group.Tag) err := rows.Scan(&group.ID, &group.Name, &group.PermissionsText, &group.Is_Mod, &group.Is_Admin, &group.Is_Banned, &group.Tag)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
// Ugh, you really shouldn't physically delete these items, it makes a big mess of things // Ugh, you really shouldn't physically delete these items, it makes a big mess of things
@ -633,7 +634,7 @@ func init_database(err error) {
err = json.Unmarshal(group.PermissionsText, &group.Perms) err = json.Unmarshal(group.PermissionsText, &group.Perms)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
if !nogrouplog { if !nogrouplog {
fmt.Println(group.Name + ": ") fmt.Println(group.Name + ": ")
@ -645,7 +646,7 @@ func init_database(err error) {
} }
err = rows.Err() err = rows.Err()
if err != nil { if err != nil {
log.Fatal(err) return err
} }
groupCapCount = i groupCapCount = i
@ -659,7 +660,7 @@ func init_database(err error) {
//rows, err = db.Query("SELECT fid, name, active, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime FROM forums") //rows, err = db.Query("SELECT fid, name, active, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime FROM forums")
rows, err = db.Query("select fid, name, active, preset, topicCount, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime from forums order by fid asc") rows, err = db.Query("select fid, name, active, preset, topicCount, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime from forums order by fid asc")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer rows.Close() defer rows.Close()
@ -668,7 +669,7 @@ func init_database(err error) {
forum := Forum{ID:0,Name:"",Active:true,Preset:"all"} forum := Forum{ID:0,Name:"",Active:true,Preset:"all"}
err := rows.Scan(&forum.ID, &forum.Name, &forum.Active, &forum.Preset, &forum.TopicCount, &forum.LastTopic, &forum.LastTopicID, &forum.LastReplyer, &forum.LastReplyerID, &forum.LastTopicTime) err := rows.Scan(&forum.ID, &forum.Name, &forum.Active, &forum.Preset, &forum.TopicCount, &forum.LastTopic, &forum.LastTopicID, &forum.LastReplyer, &forum.LastReplyerID, &forum.LastTopicTime)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
// Ugh, you really shouldn't physically delete these items, it makes a big mess of things // Ugh, you really shouldn't physically delete these items, it makes a big mess of things
@ -680,7 +681,7 @@ func init_database(err error) {
/*if forum.LastTopicID != 0 { /*if forum.LastTopicID != 0 {
forum.LastTopicTime, err = relative_time(forum.LastTopicTime) forum.LastTopicTime, err = relative_time(forum.LastTopicTime)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
} else { } else {
forum.LastTopic = "None" forum.LastTopic = "None"
@ -692,7 +693,7 @@ func init_database(err error) {
} }
err = rows.Err() err = rows.Err()
if err != nil { if err != nil {
log.Fatal(err) return err
} }
forumCapCount = i forumCapCount = i
@ -702,7 +703,7 @@ func init_database(err error) {
log.Print("Loading the forum permissions") log.Print("Loading the forum permissions")
rows, err = db.Query("select gid, fid, permissions from forums_permissions order by gid asc, fid asc") rows, err = db.Query("select gid, fid, permissions from forums_permissions order by gid asc, fid asc")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer rows.Close() defer rows.Close()
@ -716,11 +717,11 @@ func init_database(err error) {
var pperms ForumPerms var pperms ForumPerms
err := rows.Scan(&gid, &fid, &perms) err := rows.Scan(&gid, &fid, &perms)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
err = json.Unmarshal(perms, &pperms) err = json.Unmarshal(perms, &pperms)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
pperms.ExtData = make(map[string]bool) pperms.ExtData = make(map[string]bool)
pperms.Overrides = true pperms.Overrides = true
@ -763,7 +764,7 @@ func init_database(err error) {
log.Print("Loading the settings.") log.Print("Loading the settings.")
rows, err = db.Query("select name, content, type, constraints from settings") rows, err = db.Query("select name, content, type, constraints from settings")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer rows.Close() defer rows.Close()
@ -774,22 +775,22 @@ func init_database(err error) {
for rows.Next() { for rows.Next() {
err := rows.Scan(&sname, &scontent, &stype, &sconstraints) err := rows.Scan(&sname, &scontent, &stype, &sconstraints)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
errmsg := parseSetting(sname, scontent, stype, sconstraints) errmsg := parseSetting(sname, scontent, stype, sconstraints)
if errmsg != "" { if errmsg != "" {
log.Fatal(err) return err
} }
} }
err = rows.Err() err = rows.Err()
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Loading the plugins.") log.Print("Loading the plugins.")
rows, err = db.Query("select uname, active from plugins") rows, err = db.Query("select uname, active from plugins")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer rows.Close() defer rows.Close()
@ -798,7 +799,7 @@ func init_database(err error) {
for rows.Next() { for rows.Next() {
err := rows.Scan(&uname, &active) err := rows.Scan(&uname, &active)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
// Was the plugin deleted at some point? // Was the plugin deleted at some point?
@ -811,13 +812,13 @@ func init_database(err error) {
} }
err = rows.Err() err = rows.Err()
if err != nil { if err != nil {
log.Fatal(err) return err
} }
log.Print("Loading the themes.") log.Print("Loading the themes.")
rows, err = db.Query("select `uname`, `default` from `themes`") rows, err = db.Query("select `uname`, `default` from `themes`")
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer rows.Close() defer rows.Close()
@ -825,7 +826,7 @@ func init_database(err error) {
for rows.Next() { for rows.Next() {
err := rows.Scan(&uname, &defaultThemeSwitch) err := rows.Scan(&uname, &defaultThemeSwitch)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
// Was the theme deleted at some point? // Was the theme deleted at some point?
@ -847,6 +848,7 @@ func init_database(err error) {
} }
err = rows.Err() err = rows.Err()
if err != nil { if err != nil {
log.Fatal(err) return err
} }
return nil
} }

View File

@ -907,6 +907,7 @@ func route_panel_groups_edit_perms(w http.ResponseWriter, r *http.Request){
globalPerms = append(globalPerms, NameLangToggle{"EditSettings",GetGlobalPermPhrase("EditSettings"),group.Perms.EditSettings}) globalPerms = append(globalPerms, NameLangToggle{"EditSettings",GetGlobalPermPhrase("EditSettings"),group.Perms.EditSettings})
globalPerms = append(globalPerms, NameLangToggle{"ManageThemes",GetGlobalPermPhrase("ManageThemes"),group.Perms.ManageThemes}) globalPerms = append(globalPerms, NameLangToggle{"ManageThemes",GetGlobalPermPhrase("ManageThemes"),group.Perms.ManageThemes})
globalPerms = append(globalPerms, NameLangToggle{"ManagePlugins",GetGlobalPermPhrase("ManagePlugins"),group.Perms.ManagePlugins}) globalPerms = append(globalPerms, NameLangToggle{"ManagePlugins",GetGlobalPermPhrase("ManagePlugins"),group.Perms.ManagePlugins})
globalPerms = append(globalPerms, NameLangToggle{"ViewAdminLogs",GetGlobalPermPhrase("ViewAdminLogs"),group.Perms.ViewAdminLogs})
globalPerms = append(globalPerms, NameLangToggle{"ViewIPs",GetGlobalPermPhrase("ViewIPs"),group.Perms.ViewIPs}) globalPerms = append(globalPerms, NameLangToggle{"ViewIPs",GetGlobalPermPhrase("ViewIPs"),group.Perms.ViewIPs})
pi := EditGroupPermsPage{"Group Editor",user,noticeList,group.ID,group.Name,localPerms,globalPerms,nil} pi := EditGroupPermsPage{"Group Editor",user,noticeList,group.ID,group.Name,localPerms,globalPerms,nil}
@ -1298,7 +1299,7 @@ func route_panel_logs_mod(w http.ResponseWriter, r *http.Request){
if !ok { if !ok {
return return
} }
if !user.Is_Super_Mod || !user.Perms.ManageThemes { if !user.Is_Super_Mod {
NoPermissions(w,r,user) NoPermissions(w,r,user)
return return
} }

View File

@ -45,6 +45,7 @@ var GlobalPermList []string = []string{
"EditSettings", "EditSettings",
"ManageThemes", "ManageThemes",
"ManagePlugins", "ManagePlugins",
"ViewAdminLogs",
"ViewIPs", "ViewIPs",
} }
@ -75,6 +76,7 @@ type Perms struct
EditSettings bool EditSettings bool
ManageThemes bool ManageThemes bool
ManagePlugins bool ManagePlugins bool
ViewAdminLogs bool
ViewIPs bool ViewIPs bool
// Forum permissions // Forum permissions
@ -148,6 +150,7 @@ func init() {
EditSettings: true, EditSettings: true,
ManageThemes: true, ManageThemes: true,
ManagePlugins: true, ManagePlugins: true,
ViewAdminLogs: true,
ViewIPs: true, ViewIPs: true,
ViewTopic: true, ViewTopic: true,

View File

@ -24,6 +24,7 @@ var global_perm_phrases map[string]string = map[string]string{
"EditSettings": "Can edit settings", "EditSettings": "Can edit settings",
"ManageThemes": "Can manage themes", "ManageThemes": "Can manage themes",
"ManagePlugins": "Can manage plugins", "ManagePlugins": "Can manage plugins",
"ViewAdminLogs": "Can view the administrator action logs",
"ViewIPs": "Can view IP addresses", "ViewIPs": "Can view IP addresses",
} }

View File

@ -34,21 +34,16 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return return
} }
var /*extra_data, */prefix string
if req.URL.Path[len(req.URL.Path) - 1] != '/' {
//extra_data = req.URL.Path[strings.LastIndexByte(req.URL.Path,'/') + 1:]
prefix = req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/') + 1]
} else {
prefix = req.URL.Path
}
router.mu.RLock() router.mu.RLock()
handle, ok := router.routes[req.URL.Path] handle, ok := router.routes[prefix]
if ok {
router.mu.RUnlock()
handle(w,req)
return
}
if req.URL.Path[len(req.URL.Path) - 1] == '/' {
router.mu.RUnlock()
NotFound(w,req)
return
}
handle, ok = router.routes[req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/') + 1]]
if ok { if ok {
router.mu.RUnlock() router.mu.RUnlock()
handle(w,req) handle(w,req)
@ -56,13 +51,6 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
} }
//fmt.Println(req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/')]) //fmt.Println(req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/')])
handle, ok = router.routes[req.URL.Path + "/"]
if ok {
router.mu.RUnlock()
handle(w,req)
return
}
router.mu.RUnlock() router.mu.RUnlock()
NotFound(w,req) NotFound(w,req)
return return

38
router_gen/gen_router.go Normal file
View File

@ -0,0 +1,38 @@
// Code generated by. DO NOT EDIT.
/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */
package main
import "net/http"
type GenRouter struct {
UploadHandler http.Handler
}
func NewGenRouter() *GenRouter {
fs_u := http.FileServer(http.Dir("./uploads"))
return &GenRouter{http.StripPrefix("/uploads/",fs_u).ServeHTTP}
}
func (router *GenRouter) Handle(_ string, _ http.Handler) {
}
func (router *GenRouter) HandleFunc(_ string, _ func(http.ResponseWriter, *http.Request)) {
}
func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var extra_data string
if req.URL.Path[len(req.URL.Path) - 1] != '/' {
extra_data = req.URL.Path[strings.LastIndexByte(req.URL.Path,'/') + 1:]
req.URL.Path = req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/') + 1]
}
switch(req.URL.Path) {
case "/overview/":
route_overview(w http.ResponseWriter, req *http.Request)
case "/pages/":
route_custom_page(w http.ResponseWriter, req *http.Request, &extra_data)
case "/topics/":
route_topics(w http.ResponseWriter, req *http.Request, &groups, &forums)
case "/uploads/": UploadHandler(w,req)
default: NotFound(w,req)
}
}

75
router_gen/main.go Normal file
View File

@ -0,0 +1,75 @@
/* WIP Under Construction */
package main
import "log"
import "fmt"
//import "strings"
import "os"
var route_list []Route
var route_groups []RouteGroup
func main() {
fmt.Println("Generating the router...")
// Load all the routes...
routes()
var out string
var fdata string = "// Code generated by. DO NOT EDIT.\n/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */\n"
for _, route := range route_list {
out += "\n\t\tcase \"" + route.Path + "\":\n\t\t\t" + route.Name+ "(w http.ResponseWriter, req *http.Request"
for _, item := range route.Vars {
out += ", " + item
}
out += ")"
}
fdata += `package main
import "net/http"
type GenRouter struct {
UploadHandler http.Handler
}
func NewGenRouter() *GenRouter {
fs_u := http.FileServer(http.Dir("./uploads"))
return &GenRouter{http.StripPrefix("/uploads/",fs_u).ServeHTTP}
}
func (router *GenRouter) Handle(_ string, _ http.Handler) {
}
func (router *GenRouter) HandleFunc(_ string, _ func(http.ResponseWriter, *http.Request)) {
}
func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var extra_data string
if req.URL.Path[len(req.URL.Path) - 1] != '/' {
extra_data = req.URL.Path[strings.LastIndexByte(req.URL.Path,'/') + 1:]
req.URL.Path = req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/') + 1]
}
switch(req.URL.Path) {` + out + `
case "/uploads/": UploadHandler(w,req)
default: NotFound(w,req)
}
}
`
write_file("./gen_router.go",fdata)
fmt.Println("Successfully generated the router")
}
func write_file(name string, content string) {
f, err := os.Create(name)
if err != nil {
log.Fatal(err)
}
_, err = f.WriteString(content)
if err != nil {
log.Fatal(err)
}
f.Sync()
f.Close()
}

27
router_gen/routes.go Normal file
View File

@ -0,0 +1,27 @@
package main
type Route struct {
Name string
Path string
Vars []string
}
type RouteGroup struct {
Path string
Routes []Route
}
func addRoute(fname string, path string, vars ...string) {
route_list = append(route_list,Route{fname,path,vars})
}
func addRouteGroup(path string, routes ...Route) {
route_groups = append(route_groups,RouteGroup{path,routes})
}
func routes() {
//addRoute("route_static","/static/","&extra_data")
addRoute("route_overview","/overview/")
addRoute("route_custom_page","/pages/","&extra_data")
addRoute("route_topics","/topics/","&groups","&forums")
}

View File

@ -57,23 +57,26 @@ type CTemplateSet struct
func (c *CTemplateSet) compile_template(name string, dir string, expects string, expectsInt interface{}, varList map[string]VarItem) (out string) { func (c *CTemplateSet) compile_template(name string, dir string, expects string, expectsInt interface{}, varList map[string]VarItem) (out string) {
c.dir = dir c.dir = dir
c.doImports = true c.doImports = true
c.funcMap = make(map[string]interface{}) c.funcMap = map[string]interface{}{
c.funcMap["and"] = "&&" "and": "&&",
c.funcMap["not"] = "!" "not": "!",
c.funcMap["or"] = "||" "or": "||",
c.funcMap["eq"] = true "eq": true,
c.funcMap["ge"] = true "ge": true,
c.funcMap["gt"] = true "gt": true,
c.funcMap["le"] = true "le": true,
c.funcMap["lt"] = true "lt": true,
c.funcMap["ne"] = true "ne": true,
c.funcMap["add"] = true "add": true,
c.funcMap["subtract"] = true "subtract": true,
c.funcMap["multiply"] = true "multiply": true,
c.funcMap["divide"] = true "divide": true,
c.importMap = make(map[string]string) }
c.importMap["io"] = "io"
c.importMap["strconv"] = "strconv" c.importMap = map[string]string{
"io":"io",
"strconv":"strconv",
}
c.varList = varList c.varList = varList
//c.pVarList = "" //c.pVarList = ""
//c.pVarPosition = 0 //c.pVarPosition = 0

View File

@ -0,0 +1,29 @@
{{template "header.html" . }}
<div class="colstack_left">
<div class="colstack_item colstack_head">
<div class="rowitem rowhead"><a href="/panel/logs/mod/">Logs</a></div>
</div>
<div class="colstack_item">
<div class="rowitem passive"><a href="/panel/logs/mod/">Moderation Logs</a></div>
{{if .CurrentUser.Perms.ViewAdminLogs}}<div class="rowitem passive"><a>Administration Logs</a></div>{{end}}
{{if .CurrentUser.Perms.ViewAdminLogs}}<div class="rowitem passive"><a>System Logs</a></div>{{end}}
</div>
{{template "panel-inner-menu.html" . }}
</div>
<div class="colstack_right">
<div class="colstack_item colstack_head">
<div class="rowitem rowhead"><a>Administration Logs</a></div>
</div>
<div class="colstack_item">
{{range .Logs}}
<div class="rowitem" style="font-weight: normal;text-transform: none;">
<a style="font-size: 17px;">{{.Action}}</a><br />
<small style="margin-left: 2px;">IP: {{.IPAddress}}</small>
<span style="float: right;">
<span style="font-size: 16px;position:relative;top: -2px;">{{.DoneAt}}</span>
</span>
</div>
{{end}}
</div>
</div>
{{template "footer.html" . }}

View File

@ -1,5 +1,15 @@
{{template "header.html" . }} {{template "header.html" . }}
{{template "panel-menu.html" . }} <div class="colstack_left">
<div class="colstack_item colstack_head">
<div class="rowitem rowhead"><a href="/panel/logs/mod/">Logs</a></div>
</div>
<div class="colstack_item">
<div class="rowitem passive"><a href="/panel/logs/mod/">Moderation Logs</a></div>
{{if .CurrentUser.Perms.ViewAdminLogs}}<div class="rowitem passive"><a>Administration Logs</a></div>{{end}}
{{if .CurrentUser.Perms.ViewAdminLogs}}<div class="rowitem passive"><a>System Logs</a></div>{{end}}
</div>
{{template "panel-inner-menu.html" . }}
</div>
<div class="colstack_right"> <div class="colstack_right">
<div class="colstack_item colstack_head"> <div class="colstack_item colstack_head">
<div class="rowitem rowhead"><a>Moderation Logs</a></div> <div class="rowitem rowhead"><a>Moderation Logs</a></div>