From bf851bd9fc45288744e18f50d309b15e040c4173 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 27 Oct 2018 13:21:02 +1000 Subject: [PATCH] We now use Go 1.11 modules. This should help with build times, deployment and development, although it does mean that the minimum requirement for Gosora has been bumped up from Go 1.10 to Go 1.11 Added support for dyntmpl to the template system. The Account Dashboard now sort of uses dyntmpl, more work needed here. Renamed the pre_render_view_topic hook to pre_render_topic. Added the GetCurrentLangPack() function. Added the alerts_no_new_alerts phrase. Added the account_level_list phrase. Refactored the route rename logic in the patcher to cut down on the amount of boilerplate. Added more route renames to the patcher. You will need to run the patcher / updater in this commit. --- .gitignore | 2 +- README.md | 4 +- build-linux | 10 +- build-linux-nowebsockets | 10 +- build-nowebsockets.bat | 4 +- build.bat | 4 +- cmd/install/install.go | 320 ++++++++++++++ {query_gen => cmd/query_gen}/build.bat | 0 {query_gen => cmd/query_gen}/main.go | 4 +- {query_gen => cmd/query_gen}/run.bat | 0 {query_gen => cmd/query_gen}/spitter.go | 2 +- {query_gen => cmd/query_gen}/tables.go | 2 +- common/alerts.go | 4 +- common/attachments.go | 2 +- common/audit_logs.go | 2 +- common/auth.go | 4 +- common/common.go | 11 +- common/counters/agents.go | 4 +- common/counters/forums.go | 4 +- common/counters/langs.go | 4 +- common/counters/posts.go | 4 +- common/counters/referrers.go | 4 +- common/counters/requests.go | 4 +- common/counters/routes.go | 4 +- common/counters/systems.go | 4 +- common/counters/topics.go | 4 +- common/counters/topics_views.go | 4 +- common/email_store.go | 2 +- common/extend.go | 4 +- common/files.go | 2 +- common/forum.go | 2 +- common/forum_perms.go | 2 +- common/forum_perms_store.go | 2 +- common/forum_store.go | 2 +- common/group.go | 2 +- common/group_store.go | 2 +- common/ip_search.go | 2 +- common/menu_store.go | 2 +- common/menus.go | 2 +- common/mfa_store.go | 2 +- common/misc_logs.go | 2 +- common/page_store.go | 2 +- common/pages.go | 2 + common/permissions.go | 2 +- common/phrases.go | 5 + common/poll_store.go | 2 +- common/profile_reply.go | 2 +- common/profile_reply_store.go | 2 +- common/reply.go | 2 +- common/reply_store.go | 2 +- common/report_store.go | 2 +- common/settings.go | 2 +- common/subscription.go | 2 +- common/tasks.go | 2 +- common/template_init.go | 40 +- common/templates/templates.go | 37 ++ common/theme_list.go | 2 +- common/thumbnailer.go | 2 +- common/topic.go | 2 +- common/topic_list.go | 2 +- common/topic_store.go | 2 +- common/user.go | 2 +- common/user_store.go | 2 +- common/widgets.go | 2 +- common/word_filters.go | 2 +- database.go | 2 +- docs/installation.md | 4 +- experimental/plugin_hyperdrive.go | 2 +- extend/guilds/lib/guild_store.go | 2 +- extend/guilds/lib/guilds.go | 4 +- .../guilds/plugin_guilds.go | 5 +- gen_mssql.go | 2 +- gen_mysql.go | 4 +- gen_pgsql.go | 2 +- gen_router.go | 8 +- gen_tables.go | 30 +- general_test.go | 8 +- go.mod | 21 + go.sum | 89 ++++ install-docker | 6 +- install-linux | 6 +- install.bat | 2 +- install/install.go | 332 ++------------ install/install/install.go | 48 -- install/{install => }/mssql.go | 2 +- install/{install => }/mysql.go | 2 +- install/{install => }/pgsql.go | 2 +- install/{install => }/utils.go | 0 langs/english.json | 2 + main.go | 12 +- misc_test.go | 2 +- mssql.go | 4 +- mysql.go | 4 +- patcher/main.go | 4 +- patcher/patches.go | 413 ++++++------------ patcher/utils.go | 2 +- pgsql.go | 4 +- plugin_adventure.go | 2 +- plugin_bbcode.go | 2 +- plugin_heythere.go | 2 +- plugin_markdown.go | 3 +- plugin_skeleton.go | 2 +- pre-run-linux | 6 +- query_gen/{lib => }/acc_builders.go | 0 query_gen/{lib => }/accumulator.go | 0 query_gen/{lib => }/builder.go | 0 query_gen/{lib => }/install.go | 0 query_gen/{lib => }/micro_builders.go | 0 query_gen/{lib => }/mssql.go | 2 +- query_gen/{lib => }/mysql.go | 4 +- query_gen/{lib => }/pgsql.go | 2 +- query_gen/{lib => }/querygen.go | 2 +- query_gen/{lib => }/transaction.go | 0 query_gen/{lib => }/utils.go | 0 router.go | 2 +- router_gen/main.go | 8 +- router_gen/routes.go | 4 +- routes.go | 2 +- routes/account.go | 63 +-- routes/api.go | 2 +- routes/common.go | 17 + routes/forum.go | 6 +- routes/forum_list.go | 2 +- routes/misc.go | 4 +- routes/moderate.go | 2 +- routes/panel/analytics.go | 4 +- routes/panel/backups.go | 2 +- routes/panel/common.go | 2 +- routes/panel/dashboard.go | 5 +- routes/panel/debug.go | 4 +- routes/panel/forums.go | 2 +- routes/panel/groups.go | 8 +- routes/panel/logs.go | 2 +- routes/panel/pages.go | 2 +- routes/panel/plugins.go | 6 +- routes/panel/settings.go | 2 +- routes/panel/themes.go | 11 +- routes/panel/users.go | 2 +- routes/panel/word_filters.go | 2 +- routes/poll.go | 4 +- routes/profile.go | 4 +- routes/reply.go | 4 +- routes/reports.go | 4 +- routes/topic.go | 27 +- routes/topic_list.go | 2 +- routes/user.go | 2 +- run-linux | 6 +- run-linux-nowebsockets | 6 +- run-nowebsockets.bat | 2 +- run.bat | 2 +- run_mssql.bat | 2 +- run_tests.bat | 2 +- run_tests_mssql.bat | 2 +- schema/schema.json | 4 +- templates/account.html | 6 + templates/account_own_edit.html | 11 +- templates/header.html | 2 +- themes/nox/public/account.css | 48 +- themes/nox/public/panel.css | 54 +-- tickloop.go | 2 +- 160 files changed, 945 insertions(+), 1053 deletions(-) create mode 100644 cmd/install/install.go rename {query_gen => cmd/query_gen}/build.bat (100%) rename {query_gen => cmd/query_gen}/main.go (99%) rename {query_gen => cmd/query_gen}/run.bat (100%) rename {query_gen => cmd/query_gen}/spitter.go (95%) rename {query_gen => cmd/query_gen}/tables.go (99%) rename plugin_guilds.go => extend/guilds/plugin_guilds.go (98%) create mode 100644 go.mod create mode 100644 go.sum delete mode 100644 install/install/install.go rename install/{install => }/mssql.go (98%) rename install/{install => }/mysql.go (99%) rename install/{install => }/pgsql.go (98%) rename install/{install => }/utils.go (100%) rename query_gen/{lib => }/acc_builders.go (100%) rename query_gen/{lib => }/accumulator.go (100%) rename query_gen/{lib => }/builder.go (100%) rename query_gen/{lib => }/install.go (100%) rename query_gen/{lib => }/micro_builders.go (100%) rename query_gen/{lib => }/mssql.go (99%) rename query_gen/{lib => }/mysql.go (99%) rename query_gen/{lib => }/pgsql.go (99%) rename query_gen/{lib => }/querygen.go (98%) rename query_gen/{lib => }/transaction.go (100%) rename query_gen/{lib => }/utils.go (100%) create mode 100644 templates/account.html diff --git a/.gitignore b/.gitignore index ed5fb9d1..9c39ffe1 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,5 @@ QueryGen RouterGen Patcher Gosora -Install +Installer template_*.go \ No newline at end of file diff --git a/README.md b/README.md index 502042dd..334d6c78 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Other modern features like alerts, likes, advanced dashboard with live stats (CP # Requirements -Go 1.10 or newer - You will need to install this. Pick the .msi, if you want everything sorted out for you rather than having to go around updating the environment settings. https://golang.org/doc/install +Go 1.11 or newer - You will need to install this. Pick the .msi, if you want everything sorted out for you rather than having to go around updating the environment settings. https://golang.org/doc/install For Ubuntu, you can consult: https://tecadmin.net/install-go-on-ubuntu/ You will also want to run `ln -s /usr/local/go/bin/go` (replace /usr/local with where ever you put Go), so that go becomes visible to other users. @@ -135,7 +135,7 @@ These are the libraries and pieces of software which Gosora relies on to functio A few of these like Rez aren't currently in use, but are things we think we'll need in the very near future and want to have those things ready, so that we can quickly slot them in. -* Go 1.10+ +* Go 1.11+ * MariaDB (or any other MySQL compatible database engine). We'll allow other database engines in the future. diff --git a/build-linux b/build-linux index d89507a8..0a0f3d85 100644 --- a/build-linux +++ b/build-linux @@ -13,10 +13,10 @@ echo "Running the router generator" ./RouterGen echo "Building the query generator" -cd ./query_gen +cd ./cmd/query_gen go build -o QueryGen -mv ./QueryGen .. -cd .. +mv ./QueryGen ../.. +cd ../.. echo "Running the query generator" ./QueryGen @@ -26,6 +26,6 @@ go build -o Gosora echo "Building the installer" cd ./install -go build -o Install -mv ./Install .. +go build -o Installer +mv ./Installer .. cd .. diff --git a/build-linux-nowebsockets b/build-linux-nowebsockets index 0abe11fa..07016fba 100644 --- a/build-linux-nowebsockets +++ b/build-linux-nowebsockets @@ -13,10 +13,10 @@ echo "Running the router generator" ./RouterGen echo "Building the query generator" -cd ./query_gen +cd ./cmd/query_gen go build -o QueryGen -mv ./QueryGen .. -cd .. +mv ./QueryGen ../.. +cd ../.. echo "Running the query generator" ./QueryGen @@ -26,6 +26,6 @@ go build -o Gosora -tags no_ws echo "Building the installer" cd ./install -go build -o Install -mv ./Install .. +go build -o Installer +mv ./Installer .. cd .. diff --git a/build-nowebsockets.bat b/build-nowebsockets.bat index a23d6e38..b18b8c80 100644 --- a/build-nowebsockets.bat +++ b/build-nowebsockets.bat @@ -20,7 +20,7 @@ if %errorlevel% neq 0 ( ) echo Building the installer -go build ./install +go build "./cmd/install" if %errorlevel% neq 0 ( pause exit /b %errorlevel% @@ -34,7 +34,7 @@ if %errorlevel% neq 0 ( ) echo Building the query generator -go build ./query_gen +go build "./cmd/query_gen" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/build.bat b/build.bat index 088fb4bd..808a450d 100644 --- a/build.bat +++ b/build.bat @@ -22,7 +22,7 @@ if %errorlevel% neq 0 ( ) echo Building the installer -go build ./install +go build "./cmd/install" if %errorlevel% neq 0 ( pause exit /b %errorlevel% @@ -36,7 +36,7 @@ if %errorlevel% neq 0 ( ) echo Building the query generator -go build ./query_gen +go build "./cmd/query_gen" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/cmd/install/install.go b/cmd/install/install.go new file mode 100644 index 00000000..ba830969 --- /dev/null +++ b/cmd/install/install.go @@ -0,0 +1,320 @@ +/* +* +* Gosora Installer +* Copyright Azareal 2017 - 2019 +* + */ +package main + +import ( + "bufio" + "errors" + "fmt" + "os" + "runtime/debug" + "strconv" + "strings" + + "github.com/Azareal/Gosora/install" +) + +var scanner *bufio.Scanner + +var siteShortName string +var siteName string +var siteURL string +var serverPort string + +var defaultAdapter = "mysql" +var defaultHost = "localhost" +var defaultUsername = "root" +var defaultDbname = "gosora" +var defaultSiteShortName = "SN" +var defaultSiteName = "Site Name" +var defaultsiteURL = "localhost" +var defaultServerPort = "80" // 8080's a good one, if you're testing and don't want it to clash with port 80 + +func main() { + // Capture panics instead of closing the window at a superhuman speed before the user can read the message on Windows + defer func() { + r := recover() + if r != nil { + fmt.Println(r) + debug.PrintStack() + pressAnyKey() + return + } + }() + + scanner = bufio.NewScanner(os.Stdin) + fmt.Println("Welcome to Gosora's Installer") + fmt.Println("We're going to take you through a few steps to help you get started :)") + adap, ok := handleDatabaseDetails() + if !ok { + err := scanner.Err() + if err != nil { + fmt.Println(err) + } else { + err = errors.New("Something went wrong!") + } + abortError(err) + return + } + + if !getSiteDetails() { + err := scanner.Err() + if err != nil { + fmt.Println(err) + } else { + err = errors.New("Something went wrong!") + } + abortError(err) + return + } + + err := adap.InitDatabase() + if err != nil { + abortError(err) + return + } + + err = adap.TableDefs() + if err != nil { + abortError(err) + return + } + + err = adap.CreateAdmin() + if err != nil { + abortError(err) + return + } + + err = adap.InitialData() + if err != nil { + abortError(err) + return + } + + configContents := []byte(`{ + "Site": { + "ShortName":"` + siteShortName + `", + "Name":"` + siteName + `", + "URL":"` + siteURL + `", + "Port":"` + serverPort + `", + "EnableSsl":false, + "EnableEmails":false, + "HasProxy":false, + "Language": "english" + }, + "Config": { + "SslPrivkey": "", + "SslFullchain": "", + "SMTPServer": "", + "SMTPUsername": "", + "SMTPPassword": "", + "SMTPPort": "25", + + "MaxRequestSizeStr":"5MB", + "UserCache":"static", + "TopicCache":"static", + "UserCacheCapacity":150, + "TopicCacheCapacity":250, + "DefaultPath":"/topics/", + "DefaultGroup":3, + "ActivationGroup":5, + "StaffCSS":"staff_post", + "DefaultForum":2, + "MinifyTemplates":true, + "BuildSlugs":true, + "ServerCount":1, + "Noavatar":"https://api.adorable.io/avatars/{width}/{id}@{site_url}.png", + "ItemsPerPage":25 + }, + "Database": { + "Adapter": "` + adap.Name() + `", + "Host": "` + adap.DBHost() + `", + "Username": "` + adap.DBUsername() + `", + "Password": "` + adap.DBPassword() + `", + "Dbname": "` + adap.DBName() + `", + "Port": "` + adap.DBPort() + `", + + "TestAdapter": "` + adap.Name() + `", + "TestHost": "", + "TestUsername": "", + "TestPassword": "", + "TestDbname": "", + "TestPort": "" + }, + "Dev": { + "DebugMode":true, + "SuperDebug":false + } +}`) + + fmt.Println("Opening the configuration file") + configFile, err := os.Create("./config/config.json") + if err != nil { + abortError(err) + return + } + + fmt.Println("Writing to the configuration file...") + _, err = configFile.Write(configContents) + if err != nil { + abortError(err) + return + } + + configFile.Sync() + configFile.Close() + fmt.Println("Finished writing to the configuration file") + + fmt.Println("Yay, you have successfully installed Gosora!") + fmt.Println("Your name is Admin and you can login with the password 'password'. Don't forget to change it! Seriously. It's really insecure.") + pressAnyKey() +} + +func abortError(err error) { + fmt.Println(err) + fmt.Println("Aborting installation...") + pressAnyKey() +} + +func handleDatabaseDetails() (adap install.InstallAdapter, ok bool) { + var dbAdapter string + var dbHost string + var dbUsername string + var dbPassword string + var dbName string + // TODO: Let the admin set the database port? + //var dbPort string + + for { + fmt.Println("Which database adapter do you wish to use? mysql, mssql, or mysql? Default: mysql") + if !scanner.Scan() { + return nil, false + } + dbAdapter := strings.TrimSpace(scanner.Text()) + if dbAdapter == "" { + dbAdapter = defaultAdapter + } + adap, ok = install.Lookup(dbAdapter) + if ok { + break + } + fmt.Println("That adapter doesn't exist") + } + fmt.Println("Set database adapter to " + dbAdapter) + + fmt.Println("Database Host? Default: " + defaultHost) + if !scanner.Scan() { + return nil, false + } + dbHost = scanner.Text() + if dbHost == "" { + dbHost = defaultHost + } + fmt.Println("Set database host to " + dbHost) + + fmt.Println("Database Username? Default: " + defaultUsername) + if !scanner.Scan() { + return nil, false + } + dbUsername = scanner.Text() + if dbUsername == "" { + dbUsername = defaultUsername + } + fmt.Println("Set database username to " + dbUsername) + + fmt.Println("Database Password? Default: ''") + if !scanner.Scan() { + return nil, false + } + dbPassword = scanner.Text() + if len(dbPassword) == 0 { + fmt.Println("You didn't set a password for this user. This won't block the installation process, but it might create security issues in the future.") + fmt.Println("") + } else { + fmt.Println("Set password to " + obfuscatePassword(dbPassword)) + } + + fmt.Println("Database Name? Pick a name you like or one provided to you. Default: " + defaultDbname) + if !scanner.Scan() { + return nil, false + } + dbName = scanner.Text() + if dbName == "" { + dbName = defaultDbname + } + fmt.Println("Set database name to " + dbName) + + adap.SetConfig(dbHost, dbUsername, dbPassword, dbName, adap.DefaultPort()) + return adap, true +} + +func getSiteDetails() bool { + fmt.Println("Okay. We also need to know some actual information about your site!") + fmt.Println("What's your site's name? Default: " + defaultSiteName) + if !scanner.Scan() { + return false + } + siteName = scanner.Text() + if siteName == "" { + siteName = defaultSiteName + } + fmt.Println("Set the site name to " + siteName) + + // ? - We could compute this based on the first letter of each word in the site's name, if it's name spans multiple words. I'm not sure how to do this for single word names. + fmt.Println("Can we have a short abbreviation for your site? Default: " + defaultSiteShortName) + if !scanner.Scan() { + return false + } + siteShortName = scanner.Text() + if siteShortName == "" { + siteShortName = defaultSiteShortName + } + fmt.Println("Set the short name to " + siteShortName) + + fmt.Println("What's your site's url? Default: " + defaultsiteURL) + if !scanner.Scan() { + return false + } + siteURL = scanner.Text() + if siteURL == "" { + siteURL = defaultsiteURL + } + fmt.Println("Set the site url to " + siteURL) + + fmt.Println("What port do you want the server to listen on? If you don't know what this means, you should probably leave it on the default. Default: " + defaultServerPort) + if !scanner.Scan() { + return false + } + serverPort = scanner.Text() + if serverPort == "" { + serverPort = defaultServerPort + } + _, err := strconv.Atoi(serverPort) + if err != nil { + fmt.Println("That's not a valid number!") + return false + } + fmt.Println("Set the server port to " + serverPort) + return true +} + +func obfuscatePassword(password string) (out string) { + for i := 0; i < len(password); i++ { + out += "*" + } + return out +} + +func pressAnyKey() { + //fmt.Println("Press any key to exit...") + fmt.Println("Please press enter to exit...") + for scanner.Scan() { + _ = scanner.Text() + return + } +} diff --git a/query_gen/build.bat b/cmd/query_gen/build.bat similarity index 100% rename from query_gen/build.bat rename to cmd/query_gen/build.bat diff --git a/query_gen/main.go b/cmd/query_gen/main.go similarity index 99% rename from query_gen/main.go rename to cmd/query_gen/main.go index 5e07a396..9c54cf95 100644 --- a/query_gen/main.go +++ b/cmd/query_gen/main.go @@ -1,5 +1,5 @@ /* WIP Under Construction */ -package main +package main // import "github.com/Azareal/Gosora/query_gen" import ( "fmt" @@ -8,7 +8,7 @@ import ( "runtime/debug" "strconv" - "./lib" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Make sure all the errors in this file propagate upwards properly diff --git a/query_gen/run.bat b/cmd/query_gen/run.bat similarity index 100% rename from query_gen/run.bat rename to cmd/query_gen/run.bat diff --git a/query_gen/spitter.go b/cmd/query_gen/spitter.go similarity index 95% rename from query_gen/spitter.go rename to cmd/query_gen/spitter.go index 8989c361..9176e710 100644 --- a/query_gen/spitter.go +++ b/cmd/query_gen/spitter.go @@ -1,7 +1,7 @@ package main import "strings" -import "./lib" +import "github.com/Azareal/Gosora/query_gen" type PrimaryKeySpitter struct { keys map[string]string diff --git a/query_gen/tables.go b/cmd/query_gen/tables.go similarity index 99% rename from query_gen/tables.go rename to cmd/query_gen/tables.go index 429c6e91..a6dcd2db 100644 --- a/query_gen/tables.go +++ b/cmd/query_gen/tables.go @@ -1,6 +1,6 @@ package main -import "./lib" +import "github.com/Azareal/Gosora/query_gen" func createTables(adapter qgen.Adapter) error { qgen.Install.CreateTable("users", "utf8mb4", "utf8mb4_general_ci", diff --git a/common/alerts.go b/common/alerts.go index d6a76630..89df2f44 100644 --- a/common/alerts.go +++ b/common/alerts.go @@ -1,7 +1,7 @@ /* * * Gosora Alerts System -* Copyright Azareal 2017 - 2018 +* Copyright Azareal 2017 - 2019 * */ package common @@ -12,7 +12,7 @@ import ( "strconv" "strings" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) type AlertStmts struct { diff --git a/common/attachments.go b/common/attachments.go index 8a73857b..a83446e3 100644 --- a/common/attachments.go +++ b/common/attachments.go @@ -3,7 +3,7 @@ package common import ( "database/sql" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var Attachments AttachmentStore diff --git a/common/audit_logs.go b/common/audit_logs.go index f10fbcb1..f9fb881e 100644 --- a/common/audit_logs.go +++ b/common/audit_logs.go @@ -3,7 +3,7 @@ package common import ( "database/sql" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var ModLogs LogStore diff --git a/common/auth.go b/common/auth.go index 46a452e3..1c096ce9 100644 --- a/common/auth.go +++ b/common/auth.go @@ -16,8 +16,8 @@ import ( "strconv" "strings" - "../query_gen/lib" - "./gauth" + "github.com/Azareal/Gosora/query_gen" + "github.com/Azareal/Gosora/common/gauth" //"golang.org/x/crypto/argon2" "golang.org/x/crypto/bcrypt" ) diff --git a/common/common.go b/common/common.go index 24c44c89..00e94349 100644 --- a/common/common.go +++ b/common/common.go @@ -1,12 +1,17 @@ -package common +/* +* +* Gosora Common Resources +* Copyright Azareal 2018 - 2019 +* + */ +package common // import "github.com/Azareal/Gosora/common" import ( "database/sql" "log" "sync/atomic" "time" - - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var SoftwareVersion = Version{Major: 0, Minor: 2, Patch: 0, Tag: "dev"} diff --git a/common/counters/agents.go b/common/counters/agents.go index e3d1c759..f23efdad 100644 --- a/common/counters/agents.go +++ b/common/counters/agents.go @@ -3,8 +3,8 @@ package counters import ( "database/sql" - ".." - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) var AgentViewCounter *DefaultAgentViewCounter diff --git a/common/counters/forums.go b/common/counters/forums.go index c33cf39b..a929f4b4 100644 --- a/common/counters/forums.go +++ b/common/counters/forums.go @@ -4,8 +4,8 @@ import ( "database/sql" "sync" - ".." - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) var ForumViewCounter *DefaultForumViewCounter diff --git a/common/counters/langs.go b/common/counters/langs.go index e1ee7c5e..c19ac687 100644 --- a/common/counters/langs.go +++ b/common/counters/langs.go @@ -1,8 +1,8 @@ package counters import "database/sql" -import ".." -import "../../query_gen/lib" +import "github.com/Azareal/Gosora/common" +import "github.com/Azareal/Gosora/query_gen" var LangViewCounter *DefaultLangViewCounter diff --git a/common/counters/posts.go b/common/counters/posts.go index 7df259c9..e935eba3 100644 --- a/common/counters/posts.go +++ b/common/counters/posts.go @@ -4,8 +4,8 @@ import ( "database/sql" "sync/atomic" - ".." - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) var PostCounter *DefaultPostCounter diff --git a/common/counters/referrers.go b/common/counters/referrers.go index 6aef587f..445db3e1 100644 --- a/common/counters/referrers.go +++ b/common/counters/referrers.go @@ -5,8 +5,8 @@ import ( "sync" "sync/atomic" - ".." - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) var ReferrerTracker *DefaultReferrerTracker diff --git a/common/counters/requests.go b/common/counters/requests.go index a9e6557b..f2f02211 100644 --- a/common/counters/requests.go +++ b/common/counters/requests.go @@ -4,8 +4,8 @@ import ( "database/sql" "sync/atomic" - ".." - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Rename this? diff --git a/common/counters/routes.go b/common/counters/routes.go index 8e8863d8..d60d2764 100644 --- a/common/counters/routes.go +++ b/common/counters/routes.go @@ -1,8 +1,8 @@ package counters import "database/sql" -import ".." -import "../../query_gen/lib" +import "github.com/Azareal/Gosora/common" +import "github.com/Azareal/Gosora/query_gen" var RouteViewCounter *DefaultRouteViewCounter diff --git a/common/counters/systems.go b/common/counters/systems.go index 636a65b4..8138be05 100644 --- a/common/counters/systems.go +++ b/common/counters/systems.go @@ -1,8 +1,8 @@ package counters import "database/sql" -import ".." -import "../../query_gen/lib" +import "github.com/Azareal/Gosora/common" +import "github.com/Azareal/Gosora/query_gen" var OSViewCounter *DefaultOSViewCounter diff --git a/common/counters/topics.go b/common/counters/topics.go index ae913800..f72908fb 100644 --- a/common/counters/topics.go +++ b/common/counters/topics.go @@ -4,8 +4,8 @@ import ( "database/sql" "sync/atomic" - ".." - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) var TopicCounter *DefaultTopicCounter diff --git a/common/counters/topics_views.go b/common/counters/topics_views.go index f473fdfb..19e114f9 100644 --- a/common/counters/topics_views.go +++ b/common/counters/topics_views.go @@ -5,8 +5,8 @@ import ( "sync" "sync/atomic" - ".." - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) var TopicViewCounter *DefaultTopicViewCounter diff --git a/common/email_store.go b/common/email_store.go index 907ca205..6a564d5d 100644 --- a/common/email_store.go +++ b/common/email_store.go @@ -1,7 +1,7 @@ package common import "database/sql" -import "../query_gen/lib" +import "github.com/Azareal/Gosora/query_gen" var Emails EmailStore diff --git a/common/extend.go b/common/extend.go index 209ad577..4261af47 100644 --- a/common/extend.go +++ b/common/extend.go @@ -15,7 +15,7 @@ import ( "sync" "sync/atomic" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var ErrPluginNotInstallable = errors.New("This plugin is not installable") @@ -218,7 +218,7 @@ var PreRenderHooks = map[string][]func(http.ResponseWriter, *http.Request, *User "pre_render_forum_list": nil, "pre_render_forum": nil, "pre_render_topic_list": nil, - "pre_render_view_topic": nil, + "pre_render_topic": nil, "pre_render_profile": nil, "pre_render_custom_page": nil, "pre_render_tmpl_page": nil, diff --git a/common/files.go b/common/files.go index 27dd4348..7f03c6ee 100644 --- a/common/files.go +++ b/common/files.go @@ -14,7 +14,7 @@ import ( "strings" "sync" - "../tmpl_client" + "github.com/Azareal/Gosora/tmpl_client" ) type SFileList map[string]SFile diff --git a/common/forum.go b/common/forum.go index 6f467b16..f9c87e65 100644 --- a/common/forum.go +++ b/common/forum.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" _ "github.com/go-sql-driver/mysql" ) diff --git a/common/forum_perms.go b/common/forum_perms.go index 523ed290..f5486d4d 100644 --- a/common/forum_perms.go +++ b/common/forum_perms.go @@ -4,7 +4,7 @@ import ( "database/sql" "encoding/json" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) // ? - Can we avoid duplicating the items in this list in a bunch of places? diff --git a/common/forum_perms_store.go b/common/forum_perms_store.go index 9eb484cf..8ef1fe64 100644 --- a/common/forum_perms_store.go +++ b/common/forum_perms_store.go @@ -5,7 +5,7 @@ import ( "encoding/json" "sync" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var FPStore ForumPermsStore diff --git a/common/forum_store.go b/common/forum_store.go index 4307e5d7..8804a145 100644 --- a/common/forum_store.go +++ b/common/forum_store.go @@ -14,7 +14,7 @@ import ( "sync" "sync/atomic" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var forumCreateMutex sync.Mutex diff --git a/common/group.go b/common/group.go index 8627d90c..110193b2 100644 --- a/common/group.go +++ b/common/group.go @@ -4,7 +4,7 @@ import ( "database/sql" "encoding/json" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var blankGroup = Group{ID: 0, Name: ""} diff --git a/common/group_store.go b/common/group_store.go index 3649e1a7..bee00cfe 100644 --- a/common/group_store.go +++ b/common/group_store.go @@ -9,7 +9,7 @@ import ( "sort" "sync" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var Groups GroupStore diff --git a/common/ip_search.go b/common/ip_search.go index 05776c22..f411891d 100644 --- a/common/ip_search.go +++ b/common/ip_search.go @@ -3,7 +3,7 @@ package common import ( "database/sql" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var IPSearch IPSearcher diff --git a/common/menu_store.go b/common/menu_store.go index 87ac3c04..5338e8bf 100644 --- a/common/menu_store.go +++ b/common/menu_store.go @@ -5,7 +5,7 @@ import ( "strconv" "sync/atomic" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var Menus *DefaultMenuStore diff --git a/common/menus.go b/common/menus.go index 9faafbf6..2da40530 100644 --- a/common/menus.go +++ b/common/menus.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) type MenuItemList []MenuItem diff --git a/common/mfa_store.go b/common/mfa_store.go index 7b064d33..2ec5ae31 100644 --- a/common/mfa_store.go +++ b/common/mfa_store.go @@ -5,7 +5,7 @@ import ( "errors" "strings" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var MFAstore MFAStore diff --git a/common/misc_logs.go b/common/misc_logs.go index 290e9037..c34f4130 100644 --- a/common/misc_logs.go +++ b/common/misc_logs.go @@ -1,7 +1,7 @@ package common import "database/sql" -import "../query_gen/lib" +import "github.com/Azareal/Gosora/query_gen" var RegLogs RegLogStore diff --git a/common/page_store.go b/common/page_store.go index 2b6da7ce..5965b3a4 100644 --- a/common/page_store.go +++ b/common/page_store.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) type CustomPageStmts struct { diff --git a/common/pages.go b/common/pages.go index 15889346..72e0d5af 100644 --- a/common/pages.go +++ b/common/pages.go @@ -157,6 +157,8 @@ type EmailListPage struct { type AccountDashPage struct { *Header + HTMLID string + TmplName string MFASetup bool CurrentScore int NextScore int diff --git a/common/permissions.go b/common/permissions.go index 2fde3313..2f82a08e 100644 --- a/common/permissions.go +++ b/common/permissions.go @@ -4,7 +4,7 @@ import ( "encoding/json" "log" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Refactor the perms system diff --git a/common/phrases.go b/common/phrases.go index 6f8d02ec..926754d1 100644 --- a/common/phrases.go +++ b/common/phrases.go @@ -276,6 +276,11 @@ func getPhrasePlaceholder(prefix string, suffix string) string { return "{lang." + prefix + "[" + suffix + "]}" } +// Please don't mutate *LanguagePack +func GetCurrentLangPack() *LanguagePack { + return currentLangPack.Load().(*LanguagePack) +} + // ? - Use runtime reflection for updating phrases? // TODO: Implement these func AddPhrase() { diff --git a/common/poll_store.go b/common/poll_store.go index 5790952a..146a7ecc 100644 --- a/common/poll_store.go +++ b/common/poll_store.go @@ -7,7 +7,7 @@ import ( "log" "strconv" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var Polls PollStore diff --git a/common/profile_reply.go b/common/profile_reply.go index e397d101..64084483 100644 --- a/common/profile_reply.go +++ b/common/profile_reply.go @@ -5,7 +5,7 @@ import ( "html" "time" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var profileReplyStmts ProfileReplyStmts diff --git a/common/profile_reply_store.go b/common/profile_reply_store.go index c9b96d2a..9b2c99f5 100644 --- a/common/profile_reply_store.go +++ b/common/profile_reply_store.go @@ -3,7 +3,7 @@ package common import ( "database/sql" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var Prstore ProfileReplyStore diff --git a/common/reply.go b/common/reply.go index d8c53518..f571e10d 100644 --- a/common/reply.go +++ b/common/reply.go @@ -12,7 +12,7 @@ import ( "html" "time" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) type ReplyUser struct { diff --git a/common/reply_store.go b/common/reply_store.go index 1f3eb8ff..943809b3 100644 --- a/common/reply_store.go +++ b/common/reply_store.go @@ -1,7 +1,7 @@ package common import "database/sql" -import "../query_gen/lib" +import "github.com/Azareal/Gosora/query_gen" var Rstore ReplyStore diff --git a/common/report_store.go b/common/report_store.go index ac7f2539..51076e8c 100644 --- a/common/report_store.go +++ b/common/report_store.go @@ -5,7 +5,7 @@ import ( "errors" "strconv" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Make the default report forum ID configurable diff --git a/common/settings.go b/common/settings.go index 6df747e7..d7452724 100644 --- a/common/settings.go +++ b/common/settings.go @@ -7,7 +7,7 @@ import ( "strings" "sync/atomic" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var SettingBox atomic.Value // An atomic value pointing to a SettingBox diff --git a/common/subscription.go b/common/subscription.go index 146c2be4..a15c03de 100644 --- a/common/subscription.go +++ b/common/subscription.go @@ -1,7 +1,7 @@ package common import "database/sql" -import "../query_gen/lib" +import "github.com/Azareal/Gosora/query_gen" var Subscriptions SubscriptionStore diff --git a/common/tasks.go b/common/tasks.go index f367eee4..f1957047 100644 --- a/common/tasks.go +++ b/common/tasks.go @@ -11,7 +11,7 @@ import ( "log" "time" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) type TaskStmts struct { diff --git a/common/template_init.go b/common/template_init.go index eeb15d3c..fca76cc5 100644 --- a/common/template_init.go +++ b/common/template_init.go @@ -4,14 +4,15 @@ import ( "html/template" "io" "log" + "math" "path/filepath" "strconv" "strings" "sync" "time" - "./alerts" - "./templates" + "github.com/Azareal/Gosora/common/alerts" + "github.com/Azareal/Gosora/common/templates" ) var Ctemplates []string @@ -27,6 +28,7 @@ type CTmpl struct { Imports []string } +// TODO: Refactor the template trees to not need these // TODO: Stop duplicating these bits of code // nolint func interpretedTopicTemplate(pi TopicPage, w io.Writer) error { @@ -122,6 +124,15 @@ var Template_ip_search_handle = func(pi IPSearchPage, w io.Writer) error { return Templates.ExecuteTemplate(w, mapping+".html", pi) } +// nolint +var Template_account_handle = func(pi AccountDashPage, w io.Writer) error { + mapping, ok := Themes[DefaultThemeBox.Load().(string)].TemplatesMap["account"] + if !ok { + mapping = "account" + } + return Templates.ExecuteTemplate(w, mapping+".html", pi) +} + func tmplInitUsers() (User, User, User) { avatar, microAvatar := BuildAvatar(62, "") user := User{62, BuildProfileURL("fake-user", 62), "Fake User", "compiler@localhost", 0, false, false, false, false, false, false, GuestPerms, make(map[string]bool), "", false, "", avatar, microAvatar, "", "", "", "", 0, 0, 0, "0.0.0.0.0", 0} @@ -171,8 +182,8 @@ func CompileTemplates() error { c := tmpl.NewCTemplateSet() c.SetConfig(config) c.SetBaseImportMap(map[string]string{ - "io": "io", - "./common": "./common", + "io": "io", + "github.com/Azareal/Gosora/common": "github.com/Azareal/Gosora/common", }) c.SetBuildTags("!no_templategen") @@ -285,6 +296,18 @@ func CompileTemplates() error { return err } + mfaSetup := false + prevScore := GetLevelScore(header.CurrentUser.Level) + currentScore := header.CurrentUser.Score - prevScore + nextScore := GetLevelScore(header.CurrentUser.Level+1) - prevScore + perc := int(math.Ceil((float64(nextScore) / float64(currentScore)) * 100)) + + accountPage := AccountDashPage{header, "dashboard", "account_own_edit", mfaSetup, currentScore, nextScore, user.Level + 1, perc * 2} + accountTmpl, err := compile("account", "common.AccountDashPage", accountPage) + if err != nil { + return err + } + var wg sync.WaitGroup var writeTemplate = func(name string, content string) { log.Print("Writing template '" + name + "'") @@ -327,6 +350,7 @@ func CompileTemplates() error { writeTemplate("login", loginTmpl) writeTemplate("register", registerTmpl) writeTemplate("ip_search", ipSearchTmpl) + writeTemplate("account", accountTmpl) writeTemplate("error", errorTmpl) writeTemplateList(c, &wg, "./") return nil @@ -346,8 +370,8 @@ func CompileJSTemplates() error { c := tmpl.NewCTemplateSet() c.SetConfig(config) c.SetBaseImportMap(map[string]string{ - "io": "io", - "../common/alerts": "../common/alerts", + "io": "io", + "github.com/Azareal/Gosora/common/alerts": "github.com/Azareal/Gosora/common/alerts", }) c.SetBuildTags("!no_templategen") @@ -364,8 +388,8 @@ func CompileJSTemplates() error { } c.SetBaseImportMap(map[string]string{ - "io": "io", - "../common": "../common", + "io": "io", + "github.com/Azareal/Gosora/common": "github.com/Azareal/Gosora/common", }) // TODO: Fix the import loop so we don't have to use this hack anymore c.SetBuildTags("!no_templategen,tmplgentopic") diff --git a/common/templates/templates.go b/common/templates/templates.go index 0fdf75ef..79e2e1a2 100644 --- a/common/templates/templates.go +++ b/common/templates/templates.go @@ -87,6 +87,7 @@ func NewCTemplateSet() *CTemplateSet { "lang": true, "level": true, "scope": true, + "dyntmpl": true, }, } } @@ -733,6 +734,42 @@ ArgLoop: literal = true break ArgLoop case "dyntmpl": + var nameParam, pageParam, headParam string + // TODO: Implement string literals properly + // TODO: Should we check to see if pos+3 is within the bounds of the slice? + nameOperand := node.Args[pos+1].String() + pageOperand := node.Args[pos+2].String() + headOperand := node.Args[pos+3].String() + + if len(nameOperand) == 0 || len(pageOperand) == 0 || len(headOperand) == 0 { + panic("None of the three operands for function dyntmpl can be left blank") + } + if nameOperand[0] == '"' { + nameParam = nameOperand + } else { + nameParam, _ = c.compileIfVarsub(nameOperand, varholder, templateName, holdreflect) + } + if pageOperand[0] == '"' { + panic("The page operand for function dyntmpl cannot be a string") + } + if headOperand[0] == '"' { + panic("The head operand for function dyntmpl cannot be a string") + } + + pageParam, val3 := c.compileIfVarsub(pageOperand, varholder, templateName, holdreflect) + if !val3.IsValid() { + panic("val3 is invalid") + } + headParam, val4 := c.compileIfVarsub(headOperand, varholder, templateName, holdreflect) + if !val4.IsValid() { + panic("val4 is invalid") + } + val = val4 + + // TODO: Refactor this + // TODO: Call the template function directly rather than going through RunThemeTemplate to eliminate a round of indirection? + out = "{\nerr := common.RunThemeTemplate(" + headParam + ".Theme.Name," + nameParam + "," + pageParam + ",w)\n" + out += "if err != nil {\nreturn err\n}\n}\n" literal = true break ArgLoop default: diff --git a/common/theme_list.go b/common/theme_list.go index 939acd2f..b527b70e 100644 --- a/common/theme_list.go +++ b/common/theme_list.go @@ -13,7 +13,7 @@ import ( "sync" "sync/atomic" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Something more thread-safe diff --git a/common/thumbnailer.go b/common/thumbnailer.go index 514a84a3..876b73bf 100644 --- a/common/thumbnailer.go +++ b/common/thumbnailer.go @@ -8,7 +8,7 @@ import ( "os" "strconv" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" "github.com/pkg/errors" ) diff --git a/common/topic.go b/common/topic.go index f95f0174..f143b510 100644 --- a/common/topic.go +++ b/common/topic.go @@ -13,7 +13,7 @@ import ( "strconv" "time" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) // This is also in reply.go diff --git a/common/topic_list.go b/common/topic_list.go index c5285152..0f557a4c 100644 --- a/common/topic_list.go +++ b/common/topic_list.go @@ -5,7 +5,7 @@ import ( "sync" "sync/atomic" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var TopicList TopicListInt diff --git a/common/topic_store.go b/common/topic_store.go index 96b3f9d2..40b94b1c 100644 --- a/common/topic_store.go +++ b/common/topic_store.go @@ -11,7 +11,7 @@ import ( "errors" "strings" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Add the watchdog goroutine diff --git a/common/user.go b/common/user.go index 4b666f4e..e932942b 100644 --- a/common/user.go +++ b/common/user.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" "github.com/go-sql-driver/mysql" ) diff --git a/common/user_store.go b/common/user_store.go index 14f0d66f..73623e2b 100644 --- a/common/user_store.go +++ b/common/user_store.go @@ -6,7 +6,7 @@ import ( "log" "strconv" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" "golang.org/x/crypto/bcrypt" ) diff --git a/common/widgets.go b/common/widgets.go index 88af497b..1d8f2603 100644 --- a/common/widgets.go +++ b/common/widgets.go @@ -9,7 +9,7 @@ import ( "strings" "sync" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) var Docks WidgetDocks diff --git a/common/word_filters.go b/common/word_filters.go index 831d1921..e22d7ec9 100644 --- a/common/word_filters.go +++ b/common/word_filters.go @@ -4,7 +4,7 @@ import ( "database/sql" "sync/atomic" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Move some features into methods on this? diff --git a/database.go b/database.go index bacc6883..9804345c 100644 --- a/database.go +++ b/database.go @@ -4,7 +4,7 @@ import ( "database/sql" "log" - "./common" + "github.com/Azareal/Gosora/common" "github.com/pkg/errors" ) diff --git a/docs/installation.md b/docs/installation.md index 04acaa28..27609bdd 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -142,13 +142,13 @@ go build ./router_gen router_gen.exe -go build ./query_gen +go build ./cmd/query_gen query_gen.exe go build -o gosora.exe -go build ./install +go build "./cmd/install" install.exe diff --git a/experimental/plugin_hyperdrive.go b/experimental/plugin_hyperdrive.go index 20bd33a6..ac038907 100644 --- a/experimental/plugin_hyperdrive.go +++ b/experimental/plugin_hyperdrive.go @@ -4,7 +4,7 @@ package main import ( "sync/atomic" - "./common" + "github.com/Azareal/Gosora/common" ) var hyperPageCache *HyperPageCache diff --git a/extend/guilds/lib/guild_store.go b/extend/guilds/lib/guild_store.go index 6490b71d..d6c30048 100644 --- a/extend/guilds/lib/guild_store.go +++ b/extend/guilds/lib/guild_store.go @@ -1,7 +1,7 @@ package guilds import "database/sql" -import "../../../query_gen/lib" +import "github.com/Azareal/Gosora/query_gen" var Gstore GuildStore diff --git a/extend/guilds/lib/guilds.go b/extend/guilds/lib/guilds.go index 8d301c0f..9a0562c8 100644 --- a/extend/guilds/lib/guilds.go +++ b/extend/guilds/lib/guilds.go @@ -1,4 +1,4 @@ -package guilds +package guilds // import "github.com/Azareal/Gosora/extend/guilds/lib" import ( "bytes" @@ -10,7 +10,7 @@ import ( "strconv" "strings" - "../../../common" + "github.com/Azareal/Gosora/common" ) // A blank list to fill out that parameter in Page for routes which don't use it diff --git a/plugin_guilds.go b/extend/guilds/plugin_guilds.go similarity index 98% rename from plugin_guilds.go rename to extend/guilds/plugin_guilds.go index d548a911..27971e44 100644 --- a/plugin_guilds.go +++ b/extend/guilds/plugin_guilds.go @@ -1,9 +1,8 @@ package main import ( - "./common" - "./extend/guilds/lib" - "./query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/extend/guilds/lib" ) // TODO: Add a better way of splitting up giant plugins like this diff --git a/gen_mssql.go b/gen_mssql.go index 8c6d0bcd..896661c4 100644 --- a/gen_mssql.go +++ b/gen_mssql.go @@ -5,7 +5,7 @@ package main import "log" import "database/sql" -import "./common" +import "github.com/Azareal/Gosora/common" // nolint type Stmts struct { diff --git a/gen_mysql.go b/gen_mysql.go index d9138e70..6a567026 100644 --- a/gen_mysql.go +++ b/gen_mysql.go @@ -6,8 +6,8 @@ package main import "log" import "database/sql" -import "./common" -//import "./query_gen/lib" +import "github.com/Azareal/Gosora/common" +//import "github.com/Azareal/Gosora/query_gen" // nolint type Stmts struct { diff --git a/gen_pgsql.go b/gen_pgsql.go index 9a479f97..bd0afdb9 100644 --- a/gen_pgsql.go +++ b/gen_pgsql.go @@ -5,7 +5,7 @@ package main import "log" import "database/sql" -import "./common" +import "github.com/Azareal/Gosora/common" // nolint type Stmts struct { diff --git a/gen_router.go b/gen_router.go index 0b7de7ee..88927be4 100644 --- a/gen_router.go +++ b/gen_router.go @@ -14,10 +14,10 @@ import ( "os" "net/http" - "./common" - "./common/counters" - "./routes" - "./routes/panel" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/common/counters" + "github.com/Azareal/Gosora/routes" + "github.com/Azareal/Gosora/routes/panel" ) var ErrNoRoute = errors.New("That route doesn't exist.") diff --git a/gen_tables.go b/gen_tables.go index cfa11187..d26d8f33 100644 --- a/gen_tables.go +++ b/gen_tables.go @@ -2,22 +2,22 @@ package main var dbTablePrimaryKeys = map[string]string{ - "users_groups_scheduler":"uid", - "replies":"rid", "attachments":"attachID", - "revisions":"reviseID", - "polls":"pollID", - "users_replies":"rid", - "activity_stream":"asid", - "users":"uid", - "pages":"pid", - "word_filters":"wfid", - "menus":"mid", - "registration_logs":"rlid", - "forums":"fid", - "users_2fa_keys":"uid", - "users_avatar_queue":"uid", "topics":"tid", - "users_groups":"gid", + "replies":"rid", + "polls":"pollID", + "users_2fa_keys":"uid", + "users_groups_scheduler":"uid", + "revisions":"reviseID", + "users_replies":"rid", + "menus":"mid", + "users":"uid", + "forums":"fid", + "activity_stream":"asid", + "word_filters":"wfid", "menu_items":"miid", + "pages":"pid", + "registration_logs":"rlid", + "users_groups":"gid", + "users_avatar_queue":"uid", } diff --git a/general_test.go b/general_test.go index e4751279..c59f4eaa 100644 --- a/general_test.go +++ b/general_test.go @@ -13,10 +13,10 @@ import ( "github.com/pkg/errors" - "./common" - "./install/install" - "./query_gen/lib" - "./routes" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/install/install" + "github.com/Azareal/Gosora/query_gen" + "github.com/Azareal/Gosora/routes" //"github.com/husobee/vestigo" ) diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..670f50e6 --- /dev/null +++ b/go.mod @@ -0,0 +1,21 @@ +module github.com/Azareal/Gosora + +require ( + cloud.google.com/go v0.31.0 // indirect + github.com/Azareal/gopsutil v0.0.0-20170716174751-0763ca4e911d + github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f // indirect + github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f + github.com/fsnotify/fsnotify v1.4.7 + github.com/go-ole/go-ole v1.2.1 // indirect + github.com/go-sql-driver/mysql v1.4.0 + github.com/gorilla/websocket v1.4.0 + github.com/lib/pq v1.0.0 + github.com/oschwald/geoip2-golang v1.2.1 + github.com/oschwald/maxminddb-golang v1.3.0 // indirect + github.com/pkg/errors v0.8.0 + github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d + golang.org/x/crypto v0.0.0-20181025213731-e84da0312774 + google.golang.org/appengine v1.2.0 // indirect + gopkg.in/sourcemap.v1 v1.0.5 // indirect + gopkg.in/src-d/go-git.v4 v4.7.1 +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..13c03fd2 --- /dev/null +++ b/go.sum @@ -0,0 +1,89 @@ +cloud.google.com/go v0.31.0 h1:o9K5MWWt2wk+d9jkGn2DAZ7Q9nUdnFLOpK9eIkDwONQ= +cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/Azareal/gopsutil v0.0.0-20170716174751-0763ca4e911d h1:biEIFfkaXGysjNAACgZ9yeCKkR3jOcARFgDewOhrwHw= +github.com/Azareal/gopsutil v0.0.0-20170716174751-0763ca4e911d/go.mod h1:BxcRRJJc1AsnFl41ujb+8dv75d1fRCRYAnAXAsFypq4= +github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f h1:5ZfJxyXo8KyX8DgGXC5B7ILL8y51fci/qYz2B4j8iLY= +github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f h1:WH0w/R4Yoey+04HhFxqZ6VX6I0d7RMyw5aXQ9UTvQPs= +github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc= +github.com/emirpasic/gods v1.9.0 h1:rUF4PuzEjMChMiNsVjdI+SyLu7rEqpQ5reNFnhC7oFo= +github.com/emirpasic/gods v1.9.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gliderlabs/ssh v0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw= +github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= +github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= +github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e h1:RgQk53JHp/Cjunrr1WlsXSZpqXn+uREuHvUVcK82CV8= +github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/oschwald/geoip2-golang v1.2.1 h1:3iz+jmeJc6fuCyWeKgtXSXu7+zvkxJbHFXkMT5FVebU= +github.com/oschwald/geoip2-golang v1.2.1/go.mod h1:0LTTzix/Ao1uMvOhAV4iLU0Lz7eCrP94qZWBTDKf0iE= +github.com/oschwald/maxminddb-golang v1.3.0 h1:oTh8IBSj10S5JNlUDg5WjJ1QdBMdeaZIkPEVfESSWgE= +github.com/oschwald/maxminddb-golang v1.3.0/go.mod h1:3jhIUymTJ5VREKyIhWm66LJiQt04F0UCDdodShpjWsY= +github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA= +github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= +github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d h1:1VUlQbCfkoSGv7qP7Y+ro3ap1P1pPZxgdGVqiTVy5C4= +github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/src-d/gcfg v1.3.0 h1:2BEDr8r0I0b8h/fOqwtxCEiq2HJu8n2JGZJQFGXWLjg= +github.com/src-d/gcfg v1.3.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/xanzy/ssh-agent v0.2.0 h1:Adglfbi5p9Z0BmK2oKU9nTG+zKfniSfnaMYB+ULd+Ro= +github.com/xanzy/ssh-agent v0.2.0/go.mod h1:0NyE30eGUDliuLEHJgYte/zncp2zdTStcOnWhgSqHD8= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181025213731-e84da0312774 h1:a4tQYYYuK9QdeO/+kEvNYyuR21S+7ve5EANok6hABhI= +golang.org/x/crypto v0.0.0-20181025213731-e84da0312774/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9 h1:lkiLiLBHGoH3XnqSLUIaBsilGMUjI+Uy2Xu2JLUtTas= +golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.2.0 h1:S0iUepdCWODXRvtE+gcRDd15L+k+k1AiHlMiMjefH24= +google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI= +gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78= +gopkg.in/src-d/go-billy.v4 v4.2.1 h1:omN5CrMrMcQ+4I8bJ0wEhOBPanIRWzFC953IiXKdYzo= +gopkg.in/src-d/go-billy.v4 v4.2.1/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk= +gopkg.in/src-d/go-git-fixtures.v3 v3.1.1 h1:XWW/s5W18RaJpmo1l0IYGqXKuJITWRFuA45iOf1dKJs= +gopkg.in/src-d/go-git-fixtures.v3 v3.1.1/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= +gopkg.in/src-d/go-git.v4 v4.7.1 h1:phAV/kNULxfYEvyInGdPuq3U2MtPpJdgmtOUF3cghkQ= +gopkg.in/src-d/go-git.v4 v4.7.1/go.mod h1:xrJH/YX8uSWewT6evfocf8qsivF18JgCN7/IMitOptY= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= diff --git a/install-docker b/install-docker index eb0717c5..08061d69 100644 --- a/install-docker +++ b/install-docker @@ -1,7 +1,7 @@ cd ./install go generate -go build -o Install -mv ./Install .. +go build -o Installer +mv ./Installer .. cd .. -./Install --dbType=mysql --dbHost=localhost --dbUser=$MYSQL_USER --dbPassword=$MYSQL_PASSWORD --dbName=$MYSQL_DATABASE --shortSiteName=$SITE_SHORT_NAME --siteName=$SITE_NAME --siteURL=$SITE_URL --serverPort=$SERVER_PORT--secureServerPort=$SECURE_SERVER_PORT \ No newline at end of file +./Installer --dbType=mysql --dbHost=localhost --dbUser=$MYSQL_USER --dbPassword=$MYSQL_PASSWORD --dbName=$MYSQL_DATABASE --shortSiteName=$SITE_SHORT_NAME --siteName=$SITE_NAME --siteURL=$SITE_URL --serverPort=$SERVER_PORT--secureServerPort=$SECURE_SERVER_PORT \ No newline at end of file diff --git a/install-linux b/install-linux index d26ffba7..78ed2028 100644 --- a/install-linux +++ b/install-linux @@ -40,9 +40,9 @@ go get -u github.com/fsnotify/fsnotify echo "Building the installer" cd ./install go generate -go build -o Install -mv ./Install .. +go build -o Installer +mv ./Installer .. cd .. echo "Running the installer" -./Install +./Installer diff --git a/install.bat b/install.bat index 3bb0b136..c6aff8d1 100644 --- a/install.bat +++ b/install.bat @@ -109,7 +109,7 @@ if %errorlevel% neq 0 ( echo Building the installer go generate -go build ./install +go build "./cmd/install" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/install/install.go b/install/install.go index 50419b22..73f89da2 100644 --- a/install/install.go +++ b/install/install.go @@ -1,320 +1,48 @@ -/* -* -* Gosora Installer -* Copyright Azareal 2017 - 2018 -* - */ -package main +package install import ( - "bufio" - "errors" "fmt" - "os" - "runtime/debug" - "strconv" - "strings" - "./install" + "github.com/Azareal/Gosora/query_gen" ) -var scanner *bufio.Scanner +var adapters = make(map[string]InstallAdapter) -var siteShortName string -var siteName string -var siteURL string -var serverPort string +type InstallAdapter interface { + Name() string + DefaultPort() string + SetConfig(dbHost string, dbUsername string, dbPassword string, dbName string, dbPort string) + InitDatabase() error + TableDefs() error + InitialData() error + CreateAdmin() error -var defaultAdapter = "mysql" -var defaultHost = "localhost" -var defaultUsername = "root" -var defaultDbname = "gosora" -var defaultSiteShortName = "SN" -var defaultSiteName = "Site Name" -var defaultsiteURL = "localhost" -var defaultServerPort = "80" // 8080's a good one, if you're testing and don't want it to clash with port 80 - -func main() { - // Capture panics instead of closing the window at a superhuman speed before the user can read the message on Windows - defer func() { - r := recover() - if r != nil { - fmt.Println(r) - debug.PrintStack() - pressAnyKey() - return - } - }() - - scanner = bufio.NewScanner(os.Stdin) - fmt.Println("Welcome to Gosora's Installer") - fmt.Println("We're going to take you through a few steps to help you get started :)") - adap, ok := handleDatabaseDetails() - if !ok { - err := scanner.Err() - if err != nil { - fmt.Println(err) - } else { - err = errors.New("Something went wrong!") - } - abortError(err) - return - } - - if !getSiteDetails() { - err := scanner.Err() - if err != nil { - fmt.Println(err) - } else { - err = errors.New("Something went wrong!") - } - abortError(err) - return - } - - err := adap.InitDatabase() - if err != nil { - abortError(err) - return - } - - err = adap.TableDefs() - if err != nil { - abortError(err) - return - } - - err = adap.CreateAdmin() - if err != nil { - abortError(err) - return - } - - err = adap.InitialData() - if err != nil { - abortError(err) - return - } - - configContents := []byte(`{ - "Site": { - "ShortName":"` + siteShortName + `", - "Name":"` + siteName + `", - "URL":"` + siteURL + `", - "Port":"` + serverPort + `", - "EnableSsl":false, - "EnableEmails":false, - "HasProxy":false, - "Language": "english" - }, - "Config": { - "SslPrivkey": "", - "SslFullchain": "", - "SMTPServer": "", - "SMTPUsername": "", - "SMTPPassword": "", - "SMTPPort": "25", - - "MaxRequestSizeStr":"5MB", - "UserCache":"static", - "TopicCache":"static", - "UserCacheCapacity":150, - "TopicCacheCapacity":250, - "DefaultPath":"/topics/", - "DefaultGroup":3, - "ActivationGroup":5, - "StaffCSS":"staff_post", - "DefaultForum":2, - "MinifyTemplates":true, - "BuildSlugs":true, - "ServerCount":1, - "Noavatar":"https://api.adorable.io/avatars/{width}/{id}@{site_url}.png", - "ItemsPerPage":25 - }, - "Database": { - "Adapter": "` + adap.Name() + `", - "Host": "` + adap.DBHost() + `", - "Username": "` + adap.DBUsername() + `", - "Password": "` + adap.DBPassword() + `", - "Dbname": "` + adap.DBName() + `", - "Port": "` + adap.DBPort() + `", - - "TestAdapter": "` + adap.Name() + `", - "TestHost": "", - "TestUsername": "", - "TestPassword": "", - "TestDbname": "", - "TestPort": "" - }, - "Dev": { - "DebugMode":true, - "SuperDebug":false - } -}`) - - fmt.Println("Opening the configuration file") - configFile, err := os.Create("./config/config.json") - if err != nil { - abortError(err) - return - } - - fmt.Println("Writing to the configuration file...") - _, err = configFile.Write(configContents) - if err != nil { - abortError(err) - return - } - - configFile.Sync() - configFile.Close() - fmt.Println("Finished writing to the configuration file") - - fmt.Println("Yay, you have successfully installed Gosora!") - fmt.Println("Your name is Admin and you can login with the password 'password'. Don't forget to change it! Seriously. It's really insecure.") - pressAnyKey() + DBHost() string + DBUsername() string + DBPassword() string + DBName() string + DBPort() string } -func abortError(err error) { - fmt.Println(err) - fmt.Println("Aborting installation...") - pressAnyKey() +func Lookup(name string) (InstallAdapter, bool) { + adap, ok := adapters[name] + return adap, ok } -func handleDatabaseDetails() (adap install.InstallAdapter, ok bool) { - var dbAdapter string - var dbHost string - var dbUsername string - var dbPassword string - var dbName string - // TODO: Let the admin set the database port? - //var dbPort string - - for { - fmt.Println("Which database adapter do you wish to use? mysql, mssql, or mysql? Default: mysql") - if !scanner.Scan() { - return nil, false - } - dbAdapter := strings.TrimSpace(scanner.Text()) - if dbAdapter == "" { - dbAdapter = defaultAdapter - } - adap, ok = install.Lookup(dbAdapter) - if ok { - break - } - fmt.Println("That adapter doesn't exist") - } - fmt.Println("Set database adapter to " + dbAdapter) - - fmt.Println("Database Host? Default: " + defaultHost) - if !scanner.Scan() { - return nil, false - } - dbHost = scanner.Text() - if dbHost == "" { - dbHost = defaultHost - } - fmt.Println("Set database host to " + dbHost) - - fmt.Println("Database Username? Default: " + defaultUsername) - if !scanner.Scan() { - return nil, false - } - dbUsername = scanner.Text() - if dbUsername == "" { - dbUsername = defaultUsername - } - fmt.Println("Set database username to " + dbUsername) - - fmt.Println("Database Password? Default: ''") - if !scanner.Scan() { - return nil, false - } - dbPassword = scanner.Text() - if len(dbPassword) == 0 { - fmt.Println("You didn't set a password for this user. This won't block the installation process, but it might create security issues in the future.") - fmt.Println("") - } else { - fmt.Println("Set password to " + obfuscatePassword(dbPassword)) - } - - fmt.Println("Database Name? Pick a name you like or one provided to you. Default: " + defaultDbname) - if !scanner.Scan() { - return nil, false - } - dbName = scanner.Text() - if dbName == "" { - dbName = defaultDbname - } - fmt.Println("Set database name to " + dbName) - - adap.SetConfig(dbHost, dbUsername, dbPassword, dbName, adap.DefaultPort()) - return adap, true -} - -func getSiteDetails() bool { - fmt.Println("Okay. We also need to know some actual information about your site!") - fmt.Println("What's your site's name? Default: " + defaultSiteName) - if !scanner.Scan() { - return false - } - siteName = scanner.Text() - if siteName == "" { - siteName = defaultSiteName - } - fmt.Println("Set the site name to " + siteName) - - // ? - We could compute this based on the first letter of each word in the site's name, if it's name spans multiple words. I'm not sure how to do this for single word names. - fmt.Println("Can we have a short abbreviation for your site? Default: " + defaultSiteShortName) - if !scanner.Scan() { - return false - } - siteShortName = scanner.Text() - if siteShortName == "" { - siteShortName = defaultSiteShortName - } - fmt.Println("Set the short name to " + siteShortName) - - fmt.Println("What's your site's url? Default: " + defaultsiteURL) - if !scanner.Scan() { - return false - } - siteURL = scanner.Text() - if siteURL == "" { - siteURL = defaultsiteURL - } - fmt.Println("Set the site url to " + siteURL) - - fmt.Println("What port do you want the server to listen on? If you don't know what this means, you should probably leave it on the default. Default: " + defaultServerPort) - if !scanner.Scan() { - return false - } - serverPort = scanner.Text() - if serverPort == "" { - serverPort = defaultServerPort - } - _, err := strconv.Atoi(serverPort) +func createAdmin() error { + fmt.Println("Creating the admin user") + hashedPassword, salt, err := BcryptGeneratePassword("password") if err != nil { - fmt.Println("That's not a valid number!") - return false + return err } - fmt.Println("Set the server port to " + serverPort) - return true -} -func obfuscatePassword(password string) (out string) { - for i := 0; i < len(password); i++ { - out += "*" + // Build the admin user query + adminUserStmt, err := qgen.Builder.SimpleInsert("users", "name, password, salt, email, group, is_super_admin, active, createdAt, lastActiveAt, lastLiked, oldestItemLikedCreatedAt, message, last_ip", "'Admin',?,?,'admin@localhost',1,1,1,UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),'','127.0.0.1'") + if err != nil { + return err } - return out -} -func pressAnyKey() { - //fmt.Println("Press any key to exit...") - fmt.Println("Please press enter to exit...") - for scanner.Scan() { - _ = scanner.Text() - return - } + // Run the admin user query + _, err = adminUserStmt.Exec(hashedPassword, salt) + return err } diff --git a/install/install/install.go b/install/install/install.go deleted file mode 100644 index 0583f51b..00000000 --- a/install/install/install.go +++ /dev/null @@ -1,48 +0,0 @@ -package install - -import ( - "fmt" - - "../../query_gen/lib" -) - -var adapters = make(map[string]InstallAdapter) - -type InstallAdapter interface { - Name() string - DefaultPort() string - SetConfig(dbHost string, dbUsername string, dbPassword string, dbName string, dbPort string) - InitDatabase() error - TableDefs() error - InitialData() error - CreateAdmin() error - - DBHost() string - DBUsername() string - DBPassword() string - DBName() string - DBPort() string -} - -func Lookup(name string) (InstallAdapter, bool) { - adap, ok := adapters[name] - return adap, ok -} - -func createAdmin() error { - fmt.Println("Creating the admin user") - hashedPassword, salt, err := BcryptGeneratePassword("password") - if err != nil { - return err - } - - // Build the admin user query - adminUserStmt, err := qgen.Builder.SimpleInsert("users", "name, password, salt, email, group, is_super_admin, active, createdAt, lastActiveAt, lastLiked, oldestItemLikedCreatedAt, message, last_ip", "'Admin',?,?,'admin@localhost',1,1,1,UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),'','127.0.0.1'") - if err != nil { - return err - } - - // Run the admin user query - _, err = adminUserStmt.Exec(hashedPassword, salt) - return err -} diff --git a/install/install/mssql.go b/install/mssql.go similarity index 98% rename from install/install/mssql.go rename to install/mssql.go index 03aec43e..7d176542 100644 --- a/install/install/mssql.go +++ b/install/mssql.go @@ -17,7 +17,7 @@ import ( "strconv" "strings" - "../../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" _ "github.com/denisenkom/go-mssqldb" ) diff --git a/install/install/mysql.go b/install/mysql.go similarity index 99% rename from install/install/mysql.go rename to install/mysql.go index 24b41ed2..3c139f5e 100644 --- a/install/install/mysql.go +++ b/install/mysql.go @@ -15,7 +15,7 @@ import ( "strconv" "strings" - "../../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" _ "github.com/go-sql-driver/mysql" ) diff --git a/install/install/pgsql.go b/install/pgsql.go similarity index 98% rename from install/install/pgsql.go rename to install/pgsql.go index e9a7de5b..f9c6ea79 100644 --- a/install/install/pgsql.go +++ b/install/pgsql.go @@ -13,7 +13,7 @@ import ( "fmt" "strings" - "../../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" _ "github.com/go-sql-driver/mysql" ) diff --git a/install/install/utils.go b/install/utils.go similarity index 100% rename from install/install/utils.go rename to install/utils.go diff --git a/langs/english.json b/langs/english.json index 62662676..940355bc 100644 --- a/langs/english.json +++ b/langs/english.json @@ -98,6 +98,7 @@ "register_username_too_long_prefix":"The username is too long, max: ", "register_email_fail":"We were unable to send the email for you to confirm that this email address belongs to you. You may not have access to some functionality until you do so. Please ask an administrator for assistance.", + "alerts_no_new_alerts":"No new alerts", "alerts_no_actor":"Unable to find the actor", "alerts_no_target_user":"Unable to find the target user", "alerts_no_linked_topic":"Unable to find the linked topic", @@ -132,6 +133,7 @@ "account_mfa":"Manage 2FA", "account_mfa_setup":"Setup 2FA", "account_email":"Email Manager", + "account_level_list":"Level Progress", "panel_dashboard":"Control Panel Dashboard", "panel_forums":"Forum Manager", diff --git a/main.go b/main.go index 57cd229f..51b6917c 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,10 @@ /* * * Gosora Main File -* Copyright Azareal 2016 - 2018 +* Copyright Azareal 2016 - 2019 * */ -package main +package main // import "github.com/Azareal/Gosora" import ( "bytes" @@ -21,10 +21,10 @@ import ( "syscall" "time" - "./common" - "./common/counters" - "./query_gen/lib" - "./routes" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/common/counters" + "github.com/Azareal/Gosora/routes" + "github.com/Azareal/Gosora/query_gen" "github.com/fsnotify/fsnotify" "github.com/pkg/errors" ) diff --git a/misc_test.go b/misc_test.go index 555844b3..0d70ae0c 100644 --- a/misc_test.go +++ b/misc_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "./common" + "github.com/Azareal/Gosora/common" ) func recordMustExist(t *testing.T, err error, errmsg string, args ...interface{}) { diff --git a/mssql.go b/mssql.go index dd6bafd4..473059ca 100644 --- a/mssql.go +++ b/mssql.go @@ -12,8 +12,8 @@ import ( "database/sql" "net/url" - "./common" - "./query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" _ "github.com/denisenkom/go-mssqldb" ) diff --git a/mysql.go b/mysql.go index 3bc0020c..595e0e25 100644 --- a/mysql.go +++ b/mysql.go @@ -11,8 +11,8 @@ package main import ( "log" - "./common" - "./query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" _ "github.com/go-sql-driver/mysql" "github.com/pkg/errors" ) diff --git a/patcher/main.go b/patcher/main.go index c21cb7af..46e695c7 100644 --- a/patcher/main.go +++ b/patcher/main.go @@ -10,8 +10,8 @@ import ( "runtime/debug" "strconv" - "../common" - "../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" _ "github.com/go-sql-driver/mysql" ) diff --git a/patcher/patches.go b/patcher/patches.go index e1a4538a..ee74ccbe 100644 --- a/patcher/patches.go +++ b/patcher/patches.go @@ -4,7 +4,7 @@ import ( "bufio" "strconv" - "../query_gen/lib" + "github.com/Azareal/Gosora/query_gen" ) func init() { @@ -16,6 +16,7 @@ func init() { addPatch(5, patch5) addPatch(6, patch6) addPatch(7, patch7) + addPatch(8, patch8) } func patch0(scanner *bufio.Scanner) (err error) { @@ -131,91 +132,29 @@ func patch0(scanner *bufio.Scanner) (err error) { } func patch1(scanner *bufio.Scanner) error { - // ! Don't reuse this function blindly, it doesn't escape apostrophes - var replaceTextWhere = func(replaceThis string, withThis string) error { - return execStmt(qgen.Builder.SimpleUpdate("viewchunks", "route = '"+withThis+"'", "route = '"+replaceThis+"'")) + var routes = map[string]string{ + "routeAccountEditCriticalSubmit": "routes.AccountEditCriticalSubmit", + "routeAccountEditAvatar": "routes.AccountEditAvatar", + "routeAccountEditAvatarSubmit": "routes.AccountEditAvatarSubmit", + "routeAccountEditUsername": "routes.AccountEditUsername", + "routeAccountEditUsernameSubmit": "routes.AccountEditUsernameSubmit", } - - err := replaceTextWhere("routeAccountEditCriticalSubmit", "routes.AccountEditCriticalSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routeAccountEditAvatar", "routes.AccountEditAvatar") - if err != nil { - return err - } - - err = replaceTextWhere("routeAccountEditAvatarSubmit", "routes.AccountEditAvatarSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routeAccountEditUsername", "routes.AccountEditUsername") - if err != nil { - return err - } - - err = replaceTextWhere("routeAccountEditUsernameSubmit", "routes.AccountEditUsernameSubmit") - if err != nil { - return err - } - - return nil + return renameRoutes(routes) } func patch2(scanner *bufio.Scanner) error { - // ! Don't reuse this function blindly, it doesn't escape apostrophes - var replaceTextWhere = func(replaceThis string, withThis string) error { - return execStmt(qgen.Builder.SimpleUpdate("viewchunks", "route = '"+withThis+"'", "route = '"+replaceThis+"'")) + var routes = map[string]string{ + "routeLogout": "routes.AccountLogout", + "routeShowAttachment": "routes.ShowAttachment", + "routeChangeTheme": "routes.ChangeTheme", + "routeProfileReplyCreateSubmit": "routes.ProfileReplyCreateSubmit", + "routeLikeTopicSubmit": "routes.LikeTopicSubmit", + "routeReplyLikeSubmit": "routes.ReplyLikeSubmit", + "routeDynamic": "routes.DynamicRoute", + "routeUploads": "routes.UploadedFile", + "BadRoute": "routes.BadRoute", } - - err := replaceTextWhere("routeLogout", "routes.AccountLogout") - if err != nil { - return err - } - - err = replaceTextWhere("routeShowAttachment", "routes.ShowAttachment") - if err != nil { - return err - } - - err = replaceTextWhere("routeChangeTheme", "routes.ChangeTheme") - if err != nil { - return err - } - - err = replaceTextWhere("routeProfileReplyCreateSubmit", "routes.ProfileReplyCreateSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routeLikeTopicSubmit", "routes.LikeTopicSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routeReplyLikeSubmit", "routes.ReplyLikeSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routeDynamic", "routes.DynamicRoute") - if err != nil { - return err - } - - err = replaceTextWhere("routeUploads", "routes.UploadedFile") - if err != nil { - return err - } - - err = replaceTextWhere("BadRoute", "routes.BadRoute") - if err != nil { - return err - } - - return nil + return renameRoutes(routes) } func patch3(scanner *bufio.Scanner) error { @@ -241,187 +180,45 @@ func patch3(scanner *bufio.Scanner) error { } func patch4(scanner *bufio.Scanner) error { - // ! Don't reuse this function blindly, it doesn't escape apostrophes - var replaceTextWhere = func(replaceThis string, withThis string) error { - return execStmt(qgen.Builder.SimpleUpdate("viewchunks", "route = '"+withThis+"'", "route = '"+replaceThis+"'")) + var routes = map[string]string{ + "routeReportSubmit": "routes.ReportSubmit", + "routeAccountEditEmail": "routes.AccountEditEmail", + "routeAccountEditEmailTokenSubmit": "routes.AccountEditEmailTokenSubmit", + "routePanelLogsRegs": "panel.LogsRegs", + "routePanelLogsMod": "panel.LogsMod", + "routePanelLogsAdmin": "panel.LogsAdmin", + "routePanelDebug": "panel.Debug", + "routePanelAnalyticsViews": "panel.AnalyticsViews", + "routePanelAnalyticsRouteViews": "panel.AnalyticsRouteViews", + "routePanelAnalyticsRouteViews": "panel.AnalyticsRouteViews", + "routePanelAnalyticsAgentViews": "panel.AnalyticsAgentViews", + "routePanelAnalyticsForumViews": "panel.AnalyticsForumViews", + "routePanelAnalyticsSystemViews": "panel.AnalyticsSystemViews", + "routePanelAnalyticsLanguageViews": "panel.AnalyticsLanguageViews", + "routePanelAnalyticsReferrerViews": "panel.AnalyticsReferrerViews", + "routePanelAnalyticsTopics": "panel.AnalyticsTopics", + "routePanelAnalyticsPosts": "panel.AnalyticsPosts", + "routePanelAnalyticsForums": "panel.AnalyticsForums", + "routePanelAnalyticsRoutes": "panel.AnalyticsRoutes", + "routePanelAnalyticsAgents": "panel.AnalyticsAgents", + "routePanelAnalyticsSystems": "panel.AnalyticsSystems", + "routePanelAnalyticsLanguages": "panel.AnalyticsLanguages", + "routePanelAnalyticsReferrers": "panel.AnalyticsReferrers", + "routePanelSettings": "panel.Settings", + "routePanelSettingEdit": "panel.SettingEdit", + "routePanelSettingEditSubmit": "panel.SettingEditSubmit", + "routePanelForums": "panel.Forums", + "routePanelForumsCreateSubmit": "panel.ForumsCreateSubmit", + "routePanelForumsDelete": "panel.ForumsDelete", + "routePanelForumsDeleteSubmit": "panel.ForumsDeleteSubmit", + "routePanelForumsEdit": "panel.ForumsEdit", + "routePanelForumsEditSubmit": "panel.ForumsEditSubmit", + "routePanelForumsEditPermsSubmit": "panel.ForumsEditPermsSubmit", + "routePanelForumsEditPermsAdvance": "panel.ForumsEditPermsAdvance", + "routePanelForumsEditPermsAdvanceSubmit": "panel.ForumsEditPermsAdvanceSubmit", + "routePanelBackups": "panel.Backups", } - - err := replaceTextWhere("routeReportSubmit", "routes.ReportSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routeAccountEditEmail", "routes.AccountEditEmail") - if err != nil { - return err - } - - err = replaceTextWhere("routeAccountEditEmailTokenSubmit", "routes.AccountEditEmailTokenSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelLogsRegs", "panel.LogsRegs") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelLogsMod", "panel.LogsMod") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelLogsAdmin", "panel.LogsAdmin") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelDebug", "panel.Debug") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsViews", "panel.AnalyticsViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsRouteViews", "panel.AnalyticsRouteViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsRouteViews", "panel.AnalyticsRouteViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsAgentViews", "panel.AnalyticsAgentViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsForumViews", "panel.AnalyticsForumViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsSystemViews", "panel.AnalyticsSystemViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsLanguageViews", "panel.AnalyticsLanguageViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsReferrerViews", "panel.AnalyticsReferrerViews") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsTopics", "panel.AnalyticsTopics") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsPosts", "panel.AnalyticsPosts") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsForums", "panel.AnalyticsForums") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsRoutes", "panel.AnalyticsRoutes") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsAgents", "panel.AnalyticsAgents") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsSystems", "panel.AnalyticsSystems") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsLanguages", "panel.AnalyticsLanguages") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelAnalyticsReferrers", "panel.AnalyticsReferrers") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelSettings", "panel.Settings") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelSettingEdit", "panel.SettingEdit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelSettingEditSubmit", "panel.SettingEditSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForums", "panel.Forums") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsCreateSubmit", "panel.ForumsCreateSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsDelete", "panel.ForumsDelete") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsDeleteSubmit", "panel.ForumsDeleteSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsEdit", "panel.ForumsEdit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsEditSubmit", "panel.ForumsEditSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsEditPermsSubmit", "panel.ForumsEditPermsSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsEditPermsAdvance", "panel.ForumsEditPermsAdvance") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelForumsEditPermsAdvanceSubmit", "panel.ForumsEditPermsAdvanceSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelBackups", "panel.Backups") + err = renameRoutes(routes) if err != nil { return err } @@ -452,32 +249,14 @@ func patch4(scanner *bufio.Scanner) error { } func patch5(scanner *bufio.Scanner) error { - // ! Don't reuse this function blindly, it doesn't escape apostrophes - var replaceTextWhere = func(replaceThis string, withThis string) error { - return execStmt(qgen.Builder.SimpleUpdate("viewchunks", "route = '"+withThis+"'", "route = '"+replaceThis+"'")) + var routes = map[string]string{ + "routePanelUsers": "panel.Users", + "routePanelUsersEdit": "panel.UsersEdit", + "routePanelUsersEditSubmit": "panel.UsersEditSubmit", + "routes.AccountEditCritical": "routes.AccountEditPassword", + "routes.AccountEditCriticalSubmit": "routes.AccountEditPasswordSubmit", } - - err := replaceTextWhere("routePanelUsers", "panel.Users") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelUsersEdit", "panel.UsersEdit") - if err != nil { - return err - } - - err = replaceTextWhere("routePanelUsersEditSubmit", "panel.UsersEditSubmit") - if err != nil { - return err - } - - err = replaceTextWhere("routes.AccountEditCritical", "routes.AccountEditPassword") - if err != nil { - return err - } - - err = replaceTextWhere("routes.AccountEditCriticalSubmit", "routes.AccountEditPasswordSubmit") + err = renameRoutes(routes) if err != nil { return err } @@ -536,3 +315,65 @@ func patch7(scanner *bufio.Scanner) error { return nil } + +func renameRoutes(routes map[string]string) error { + // ! Don't reuse this function blindly, it doesn't escape apostrophes + var replaceTextWhere = func(replaceThis string, withThis string) error { + return execStmt(qgen.Builder.SimpleUpdate("viewchunks", "route = '"+withThis+"'", "route = '"+replaceThis+"'")) + } + + for key, value := range routes { + err := replaceTextWhere(key,value) + if err != nil { + return err + } + } + + return nil +} + +func patch8(scanner *bufio.Scanner) error { + var routes = map[string]string{ + "routePanelWordFilter": "panel.WordFilters", + "routePanelWordFiltersCreateSubmit": "panel.WordFiltersCreateSubmit", + "routePanelWordFiltersEdit": "panel.WordFiltersEdit", + "routePanelWordFiltersEditSubmit": "panel.WordFiltersEditSubmit", + "routePanelWordFiltersDeleteSubmit": "panel.WordFiltersDeleteSubmit", + "routePanelPlugins": "panel.Plugins", + "routePanelPluginsActivate": "panel.PluginsActivate", + "routePanelPluginsDeactivate": "panel.PluginsDeactivate", + "routePanelPluginsInstall": "panel.PluginsInstall", + "routePanelGroups": "panel.Groups", + "routePanelGroupsEdit":"panel.GroupsEdit", + "routePanelGroupsEditPerms":"panel.GroupsEditPerms", + "routePanelGroupsEditSubmit":"panel.GroupsEditSubmit", + "routePanelGroupsEditPermsSubmit":"panel.GroupsEditPermsSubmit", + "routePanelGroupsCreateSubmit":"panel.GroupsCreateSubmit", + "routePanelThemes","panel.Themes", + "routePanelThemesSetDefault":"panel.ThemesSetDefault", + "routePanelThemesMenus":"panel.ThemesMenus", + "routePanelThemesMenusEdit":"panel.ThemesMenusEdit", + "routePanelThemesMenuItemEdit":"panel.ThemesMenuItemEdit", + "routePanelThemesMenuItemEditSubmit":"panel.ThemesMenuItemEditSubmit", + "routePanelThemesMenuItemCreateSubmit":"panel.ThemesMenuItemCreateSubmit", + "routePanelThemesMenuItemDeleteSubmit":"panel.ThemesMenuItemDeleteSubmit", + "routePanelThemesMenuItemOrderSubmit":"panel.ThemesMenuItemOrderSubmit", + "routePanelDashboard":"panel.Dashboard", + } + err := renameRoutes(routes) + if err != nil { + return err + } + + err = execStmt(qgen.Builder.CreateTable("updates", "", "", + []qgen.DBTableColumn{ + qgen.DBTableColumn{"dbVersion", "int", 0, false, false, "0"}, + }, + []qgen.DBTableKey{}, + )) + if err != nil { + return err + } + + return nil +} diff --git a/patcher/utils.go b/patcher/utils.go index fcc7593a..cb4b3556 100644 --- a/patcher/utils.go +++ b/patcher/utils.go @@ -1,7 +1,7 @@ package main import "database/sql" -import "../query_gen/lib" +import "github.com/Azareal/Gosora/query_gen" func execStmt(stmt *sql.Stmt, err error) error { if err != nil { diff --git a/pgsql.go b/pgsql.go index 6745cb98..6e372137 100644 --- a/pgsql.go +++ b/pgsql.go @@ -8,8 +8,8 @@ import ( "database/sql" "strings" - "./common" - "./query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" _ "github.com/lib/pq" ) diff --git a/plugin_adventure.go b/plugin_adventure.go index cdb61ffc..2f93104e 100644 --- a/plugin_adventure.go +++ b/plugin_adventure.go @@ -1,7 +1,7 @@ // WIP - Experimental adventure plugin, this might find a new home soon, but it's here to stress test Gosora's extensibility for now package main -import "./common" +import "github.com/Azareal/Gosora/common" func init() { common.Plugins.Add(&common.Plugin{ diff --git a/plugin_bbcode.go b/plugin_bbcode.go index ac329ab6..0e958dc0 100644 --- a/plugin_bbcode.go +++ b/plugin_bbcode.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - "./common" + "github.com/Azareal/Gosora/common" ) var bbcodeRandom *rand.Rand diff --git a/plugin_heythere.go b/plugin_heythere.go index 285f23b5..7a48ca27 100644 --- a/plugin_heythere.go +++ b/plugin_heythere.go @@ -1,6 +1,6 @@ package main -import "./common" +import "github.com/Azareal/Gosora/common" func init() { common.Plugins.Add(&common.Plugin{UName: "heythere", Name: "Hey There", Author: "Azareal", URL: "https://github.com/Azareal", Init: initHeythere, Deactivate: deactivateHeythere}) diff --git a/plugin_markdown.go b/plugin_markdown.go index 87dc1248..2f5126a9 100644 --- a/plugin_markdown.go +++ b/plugin_markdown.go @@ -1,10 +1,9 @@ package main -//import "fmt" import ( "strings" - "./common" + "github.com/Azareal/Gosora/common" ) var markdownMaxDepth = 25 // How deep the parser will go when parsing Markdown strings diff --git a/plugin_skeleton.go b/plugin_skeleton.go index 2621d193..6f638c07 100644 --- a/plugin_skeleton.go +++ b/plugin_skeleton.go @@ -1,6 +1,6 @@ package main -import "./common" +import "github.com/Azareal/Gosora/common" func init() { /* diff --git a/pre-run-linux b/pre-run-linux index 07e7dc5c..8680252d 100644 --- a/pre-run-linux +++ b/pre-run-linux @@ -16,10 +16,10 @@ echo "Running the router generator" ./RouterGen echo "Building the query generator" -cd ./query_gen +cd ./cmd/query_gen go build -o QueryGen -mv ./QueryGen .. -cd .. +mv ./QueryGen ../.. +cd ../.. echo "Running the query generator" ./QueryGen diff --git a/query_gen/lib/acc_builders.go b/query_gen/acc_builders.go similarity index 100% rename from query_gen/lib/acc_builders.go rename to query_gen/acc_builders.go diff --git a/query_gen/lib/accumulator.go b/query_gen/accumulator.go similarity index 100% rename from query_gen/lib/accumulator.go rename to query_gen/accumulator.go diff --git a/query_gen/lib/builder.go b/query_gen/builder.go similarity index 100% rename from query_gen/lib/builder.go rename to query_gen/builder.go diff --git a/query_gen/lib/install.go b/query_gen/install.go similarity index 100% rename from query_gen/lib/install.go rename to query_gen/install.go diff --git a/query_gen/lib/micro_builders.go b/query_gen/micro_builders.go similarity index 100% rename from query_gen/lib/micro_builders.go rename to query_gen/micro_builders.go diff --git a/query_gen/lib/mssql.go b/query_gen/mssql.go similarity index 99% rename from query_gen/lib/mssql.go rename to query_gen/mssql.go index e7d3fe02..cdef288c 100644 --- a/query_gen/lib/mssql.go +++ b/query_gen/mssql.go @@ -1143,7 +1143,7 @@ package main import "log" import "database/sql" -import "./common" +import "github.com/Azareal/Gosora/common" // nolint type Stmts struct { diff --git a/query_gen/lib/mysql.go b/query_gen/mysql.go similarity index 99% rename from query_gen/lib/mysql.go rename to query_gen/mysql.go index c0134c0a..68393a12 100644 --- a/query_gen/lib/mysql.go +++ b/query_gen/mysql.go @@ -754,8 +754,8 @@ package main import "log" import "database/sql" -import "./common" -//import "./query_gen/lib" +import "github.com/Azareal/Gosora/common" +//import "github.com/Azareal/Gosora/query_gen" // nolint type Stmts struct { diff --git a/query_gen/lib/pgsql.go b/query_gen/pgsql.go similarity index 99% rename from query_gen/lib/pgsql.go rename to query_gen/pgsql.go index 1f420b83..206a0cf3 100644 --- a/query_gen/lib/pgsql.go +++ b/query_gen/pgsql.go @@ -431,7 +431,7 @@ package main import "log" import "database/sql" -import "./common" +import "github.com/Azareal/Gosora/common" // nolint type Stmts struct { diff --git a/query_gen/lib/querygen.go b/query_gen/querygen.go similarity index 98% rename from query_gen/lib/querygen.go rename to query_gen/querygen.go index a0dcda3b..7455f746 100644 --- a/query_gen/lib/querygen.go +++ b/query_gen/querygen.go @@ -1,5 +1,5 @@ /* WIP Under Construction */ -package qgen +package qgen // import "github.com/Azareal/Gosora/query_gen" import ( "database/sql" diff --git a/query_gen/lib/transaction.go b/query_gen/transaction.go similarity index 100% rename from query_gen/lib/transaction.go rename to query_gen/transaction.go diff --git a/query_gen/lib/utils.go b/query_gen/utils.go similarity index 100% rename from query_gen/lib/utils.go rename to query_gen/utils.go diff --git a/router.go b/router.go index d3a58801..a1aea2e7 100644 --- a/router.go +++ b/router.go @@ -7,7 +7,7 @@ import ( "strings" "sync" - "./common" + "github.com/Azareal/Gosora/common" ) // TODO: Support the new handler signatures created by our efforts to move the PreRoute middleware into the generated router diff --git a/router_gen/main.go b/router_gen/main.go index 40dd0e1a..3e50adbb 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -226,10 +226,10 @@ import ( "os" "net/http" - "./common" - "./common/counters" - "./routes" - "./routes/panel" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/common/counters" + "github.com/Azareal/Gosora/routes" + "github.com/Azareal/Gosora/routes/panel" ) var ErrNoRoute = errors.New("That route doesn't exist.") diff --git a/router_gen/routes.go b/router_gen/routes.go index 98802c5b..9e7040b0 100644 --- a/router_gen/routes.go +++ b/router_gen/routes.go @@ -94,8 +94,6 @@ func buildTopicRoutes() { } func buildReplyRoutes() { - //router.HandleFunc("/reply/edit/", routeReplyEdit) // No js fallback - //router.HandleFunc("/reply/delete/", routeReplyDelete) // No js confirmation page? We could have a confirmation modal for the JS case replyGroup := newRouteGroup("/reply/") replyGroup.Routes( // TODO: Reduce this to 1MB for attachments for each file? @@ -103,6 +101,8 @@ func buildReplyRoutes() { Action("routes.ReplyEditSubmit", "/reply/edit/submit/", "extraData"), Action("routes.ReplyDeleteSubmit", "/reply/delete/submit/", "extraData"), Action("routes.ReplyLikeSubmit", "/reply/like/submit/", "extraData").Before("ParseForm"), + //MemberView("routes.ReplyEdit","/reply/edit/","extraData"), // No js fallback + //MemberView("routes.ReplyDelete","/reply/delete/","extraData"), // No js confirmation page? We could have a confirmation modal for the JS case ) addRouteGroup(replyGroup) } diff --git a/routes.go b/routes.go index 2fef4a7d..3f967386 100644 --- a/routes.go +++ b/routes.go @@ -15,7 +15,7 @@ import ( "strings" "unicode" - "./common" + "github.com/Azareal/Gosora/common" ) // A blank list to fill out that parameter in Page for routes which don't use it diff --git a/routes/account.go b/routes/account.go index 8efb3b02..91727704 100644 --- a/routes/account.go +++ b/routes/account.go @@ -14,8 +14,8 @@ import ( "strconv" "strings" - "../common" - "../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) // A blank list to fill out that parameter in Page for routes which don't use it @@ -31,14 +31,7 @@ func AccountLogin(w http.ResponseWriter, r *http.Request, user common.User) comm } header.Title = common.GetTitlePhrase("login") pi := common.Page{header, tList, nil} - if common.RunPreRenderHook("pre_render_login", w, r, &user, &pi) { - return nil - } - err := common.RunThemeTemplate(header.Theme.Name, "login", pi, w) - if err != nil { - return common.InternalError(err, w, r) - } - return nil + return renderTemplate("login", w, r, header, pi) } // TODO: Log failed attempted logins? @@ -203,14 +196,7 @@ func AccountRegister(w http.ResponseWriter, r *http.Request, user common.User) c header.Title = common.GetTitlePhrase("register") pi := common.Page{header, tList, nil} - if common.RunPreRenderHook("pre_render_register", w, r, &user, &pi) { - return nil - } - err := common.RunThemeTemplate(header.Theme.Name, "register", pi, w) - if err != nil { - return common.InternalError(err, w, r) - } - return nil + return renderTemplate("register", w, r, header, pi) } func isNumeric(data string) (numeric bool) { @@ -399,15 +385,8 @@ func AccountEdit(w http.ResponseWriter, r *http.Request, user common.User) commo nextScore := common.GetLevelScore(user.Level+1) - prevScore perc := int(math.Ceil((float64(nextScore) / float64(currentScore)) * 100)) - pi := common.AccountDashPage{header, mfaSetup, currentScore, nextScore, user.Level + 1, perc * 2} - if common.RunPreRenderHook("pre_render_account_own_edit", w, r, &user, &pi) { - return nil - } - err = common.Templates.ExecuteTemplate(w, "account_own_edit.html", pi) - if err != nil { - return common.InternalError(err, w, r) - } - return nil + pi := common.AccountDashPage{header, "dashboard", "account_own_edit", mfaSetup, currentScore, nextScore, user.Level + 1, perc * 2} + return renderTemplate("account", w, r, header, pi) } func AccountEditPassword(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { @@ -417,14 +396,7 @@ func AccountEditPassword(w http.ResponseWriter, r *http.Request, user common.Use } pi := common.Page{header, tList, nil} - if common.RunPreRenderHook("pre_render_account_own_edit_password", w, r, &user, &pi) { - return nil - } - err := common.Templates.ExecuteTemplate(w, "account_own_edit_password.html", pi) - if err != nil { - return common.InternalError(err, w, r) - } - return nil + return renderTemplate("account_own_edit_password", w, r, header, pi) } // TODO: Require re-authentication if the user hasn't logged in in a while @@ -711,14 +683,7 @@ func AccountEditEmail(w http.ResponseWriter, r *http.Request, user common.User) } pi := common.EmailListPage{header, emails, nil} - if common.RunPreRenderHook("pre_render_account_own_edit_email", w, r, &user, &pi) { - return nil - } - err = common.Templates.ExecuteTemplate(w, "account_own_edit_email.html", pi) - if err != nil { - return common.InternalError(err, w, r) - } - return nil + return renderTemplate("account_own_edit_email", w, r, header, pi) } // TODO: Should we make this an AnonAction so someone can do this without being logged in? @@ -763,7 +728,6 @@ func AccountEditEmailTokenSubmit(w http.ResponseWriter, r *http.Request, user co } } http.Redirect(w, r, "/user/edit/email/?verified=1", http.StatusSeeOther) - return nil } @@ -772,7 +736,7 @@ func LevelList(w http.ResponseWriter, r *http.Request, user common.User) common. if ferr != nil { return ferr } - header.Title = "Level Progress" + header.Title = common.GetTitlePhrase("account_level_list") var fScores = common.GetLevels(20) var levels = make([]common.LevelListItem, len(fScores)) @@ -791,12 +755,5 @@ func LevelList(w http.ResponseWriter, r *http.Request, user common.User) common. } pi := common.LevelListPage{header, levels[1:]} - if common.RunPreRenderHook("pre_render_level_list", w, r, &user, &pi) { - return nil - } - err := common.Templates.ExecuteTemplate(w, "level_list.html", pi) - if err != nil { - return common.InternalError(err, w, r) - } - return nil + return renderTemplate("level_list", w, r, header, pi) } diff --git a/routes/api.go b/routes/api.go index 05d54e7a..3ac88fb7 100644 --- a/routes/api.go +++ b/routes/api.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "../common" + "github.com/Azareal/Gosora/common" ) // TODO: Make this a static file somehow? Is it possible for us to put this file somewhere else? diff --git a/routes/common.go b/routes/common.go index 5e18e505..0a336e33 100644 --- a/routes/common.go +++ b/routes/common.go @@ -1,3 +1,20 @@ package routes +import ( + "net/http" + + "github.com/Azareal/Gosora/common" +) + var successJSONBytes = []byte(`{"success":"1"}`) + +func renderTemplate(tmplName string, w http.ResponseWriter, r *http.Request, header *common.Header, pi interface{}) common.RouteError { + if common.RunPreRenderHook("pre_render_"+tmplName, w, r, &header.CurrentUser, pi) { + return nil + } + err := common.RunThemeTemplate(header.Theme.Name, tmplName, pi, w) + if err != nil { + return common.InternalError(err, w, r) + } + return nil +} diff --git a/routes/forum.go b/routes/forum.go index e2c2adc6..4aecbcb9 100644 --- a/routes/forum.go +++ b/routes/forum.go @@ -6,9 +6,9 @@ import ( "strconv" "strings" - "../common" - "../common/counters" - "../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/common/counters" + "github.com/Azareal/Gosora/query_gen" ) type ForumStmts struct { diff --git a/routes/forum_list.go b/routes/forum_list.go index 7a6e22d2..c9babf47 100644 --- a/routes/forum_list.go +++ b/routes/forum_list.go @@ -4,7 +4,7 @@ import ( "log" "net/http" - "../common" + "github.com/Azareal/Gosora/common" ) func ForumList(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/misc.go b/routes/misc.go index 5c32a483..247cebcb 100644 --- a/routes/misc.go +++ b/routes/misc.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "../common" - "../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) var cacheControlMaxAge = "max-age=" + strconv.Itoa(int(common.Day)) // TODO: Make this a common.Config value diff --git a/routes/moderate.go b/routes/moderate.go index d13eee78..c2d15d84 100644 --- a/routes/moderate.go +++ b/routes/moderate.go @@ -3,7 +3,7 @@ package routes import ( "net/http" - "../common" + "github.com/Azareal/Gosora/common" ) func IPSearch(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/panel/analytics.go b/routes/panel/analytics.go index 3bc553df..10cd8ae7 100644 --- a/routes/panel/analytics.go +++ b/routes/panel/analytics.go @@ -8,8 +8,8 @@ import ( "strconv" "time" - "../../common" - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) // TODO: Move this to another file, probably common/pages.go diff --git a/routes/panel/backups.go b/routes/panel/backups.go index d5bffd29..386e967d 100644 --- a/routes/panel/backups.go +++ b/routes/panel/backups.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strconv" - "../../common" + "github.com/Azareal/Gosora/common" ) func Backups(w http.ResponseWriter, r *http.Request, user common.User, backupURL string) common.RouteError { diff --git a/routes/panel/common.go b/routes/panel/common.go index 8590bcc1..7f8873fa 100644 --- a/routes/panel/common.go +++ b/routes/panel/common.go @@ -3,7 +3,7 @@ package panel import ( "net/http" - "../../common" + "github.com/Azareal/Gosora/common" ) // A blank list to fill out that parameter in Page for routes which don't use it diff --git a/routes/panel/dashboard.go b/routes/panel/dashboard.go index 95b67750..dcaae9ee 100644 --- a/routes/panel/dashboard.go +++ b/routes/panel/dashboard.go @@ -6,8 +6,8 @@ import ( "net/http" "strconv" - "../../common" - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" "github.com/Azareal/gopsutil/mem" "github.com/pkg/errors" ) @@ -61,7 +61,6 @@ func dashMSSQLStmts() (stmts dashStmts, err error) { return stmts, err } -//routePanelDashboard func Dashboard(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { basePage, ferr := buildBasePage(w, r, &user, "dashboard", "dashboard") if ferr != nil { diff --git a/routes/panel/debug.go b/routes/panel/debug.go index 4b3cd4b5..b196ba82 100644 --- a/routes/panel/debug.go +++ b/routes/panel/debug.go @@ -6,8 +6,8 @@ import ( "strconv" "time" - "../../common" - "../../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) func Debug(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/panel/forums.go b/routes/panel/forums.go index d1d3e803..c80e4c74 100644 --- a/routes/panel/forums.go +++ b/routes/panel/forums.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "../../common" + "github.com/Azareal/Gosora/common" ) func Forums(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/panel/groups.go b/routes/panel/groups.go index d6019a09..7952cc51 100644 --- a/routes/panel/groups.go +++ b/routes/panel/groups.go @@ -5,10 +5,9 @@ import ( "net/http" "strconv" - "../../common" + "github.com/Azareal/Gosora/common" ) -// routePanelGroups func Groups(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { basePage, ferr := buildBasePage(w, r, &user, "groups", "groups") if ferr != nil { @@ -62,7 +61,6 @@ func Groups(w http.ResponseWriter, r *http.Request, user common.User) common.Rou return renderTemplate("panel_groups", w, r, user, &pi) } -//routePanelGroupsEdit func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError { basePage, ferr := buildBasePage(w, r, &user, "edit_group", "groups") if ferr != nil { @@ -111,7 +109,6 @@ func GroupsEdit(w http.ResponseWriter, r *http.Request, user common.User, sgid s return renderTemplate("panel_group_edit", w, r, user, pi) } -//routePanelGroupsEditPerms func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError { basePage, ferr := buildBasePage(w, r, &user, "edit_group", "groups") if ferr != nil { @@ -191,7 +188,6 @@ func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user common.User, s return renderTemplate("panel_group_edit_perms", w, r, user, pi) } -//routePanelGroupsEditSubmit func GroupsEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { @@ -281,7 +277,6 @@ func GroupsEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, return nil } -//routePanelGroupsEditPermsSubmit func GroupsEditPermsSubmit(w http.ResponseWriter, r *http.Request, user common.User, sgid string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { @@ -336,7 +331,6 @@ func GroupsEditPermsSubmit(w http.ResponseWriter, r *http.Request, user common.U return nil } -//routePanelGroupsCreateSubmit func GroupsCreateSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { diff --git a/routes/panel/logs.go b/routes/panel/logs.go index 696dd8d0..5433cffa 100644 --- a/routes/panel/logs.go +++ b/routes/panel/logs.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "../../common" + "github.com/Azareal/Gosora/common" ) // TODO: Link the usernames for successful registrations to the profiles diff --git a/routes/panel/pages.go b/routes/panel/pages.go index 50252467..b3044435 100644 --- a/routes/panel/pages.go +++ b/routes/panel/pages.go @@ -5,7 +5,7 @@ import ( "net/http" "strconv" - "../../common" + "github.com/Azareal/Gosora/common" ) func Pages(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/panel/plugins.go b/routes/panel/plugins.go index 3a10f4b2..49b0f629 100644 --- a/routes/panel/plugins.go +++ b/routes/panel/plugins.go @@ -5,10 +5,9 @@ import ( "log" "net/http" - "../../common" + "github.com/Azareal/Gosora/common" ) -//routePanelPlugins func Plugins(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { basePage, ferr := buildBasePage(w, r, &user, "plugins", "plugins") if ferr != nil { @@ -27,7 +26,6 @@ func Plugins(w http.ResponseWriter, r *http.Request, user common.User) common.Ro return renderTemplate("panel_plugins", w, r, user, &pi) } -//routePanelPluginsActivate // TODO: Abstract more of the plugin activation / installation / deactivation logic, so we can test all that more reliably and easily func PluginsActivate(w http.ResponseWriter, r *http.Request, user common.User, uname string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) @@ -81,7 +79,6 @@ func PluginsActivate(w http.ResponseWriter, r *http.Request, user common.User, u return nil } -//routePanelPluginsDeactivate func PluginsDeactivate(w http.ResponseWriter, r *http.Request, user common.User, uname string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { @@ -116,7 +113,6 @@ func PluginsDeactivate(w http.ResponseWriter, r *http.Request, user common.User, return nil } -//routePanelPluginsInstall func PluginsInstall(w http.ResponseWriter, r *http.Request, user common.User, uname string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { diff --git a/routes/panel/settings.go b/routes/panel/settings.go index 22f58a62..f552ca8f 100644 --- a/routes/panel/settings.go +++ b/routes/panel/settings.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "../../common" + "github.com/Azareal/Gosora/common" ) func Settings(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/panel/themes.go b/routes/panel/themes.go index 0220bd08..0cefac1b 100644 --- a/routes/panel/themes.go +++ b/routes/panel/themes.go @@ -6,10 +6,9 @@ import ( "strconv" "strings" - "../../common" + "github.com/Azareal/Gosora/common" ) -//routePanelThemes func Themes(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { basePage, ferr := buildBasePage(w, r, &user, "themes", "themes") if ferr != nil { @@ -35,7 +34,6 @@ func Themes(w http.ResponseWriter, r *http.Request, user common.User) common.Rou return renderTemplate("panel_themes", w, r, user, &pi) } -//routePanelThemesSetDefault func ThemesSetDefault(w http.ResponseWriter, r *http.Request, user common.User, uname string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { @@ -62,7 +60,6 @@ func ThemesSetDefault(w http.ResponseWriter, r *http.Request, user common.User, return nil } -//routePanelThemesMenus func ThemesMenus(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { basePage, ferr := buildBasePage(w, r, &user, "themes_menus", "themes") if ferr != nil { @@ -89,7 +86,6 @@ func ThemesMenus(w http.ResponseWriter, r *http.Request, user common.User) commo return renderTemplate("panel_themes_menus", w, r, user, &pi) } -//routePanelThemesMenusEdit func ThemesMenusEdit(w http.ResponseWriter, r *http.Request, user common.User, smid string) common.RouteError { // TODO: Something like Menu #1 for the title? basePage, ferr := buildBasePage(w, r, &user, "themes_menus_edit", "themes") @@ -137,7 +133,6 @@ func ThemesMenusEdit(w http.ResponseWriter, r *http.Request, user common.User, s return renderTemplate("panel_themes_menus_items", w, r, user, &pi) } -//routePanelThemesMenuItemEdit func ThemesMenuItemEdit(w http.ResponseWriter, r *http.Request, user common.User, sitemID string) common.RouteError { // TODO: Something like Menu #1 for the title? basePage, ferr := buildBasePage(w, r, &user, "themes_menus_edit", "themes") @@ -210,7 +205,6 @@ func themesMenuItemSetters(r *http.Request, menuItem common.MenuItem) common.Men return menuItem } -//routePanelThemesMenuItemEditSubmit func ThemesMenuItemEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, sitemID string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { @@ -242,7 +236,6 @@ func ThemesMenuItemEditSubmit(w http.ResponseWriter, r *http.Request, user commo return successRedirect("/panel/themes/menus/item/edit/"+strconv.Itoa(itemID), w, r, isJs) } -//routePanelThemesMenuItemCreateSubmit func ThemesMenuItemCreateSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { @@ -271,7 +264,6 @@ func ThemesMenuItemCreateSubmit(w http.ResponseWriter, r *http.Request, user com return successRedirect("/panel/themes/menus/item/edit/"+strconv.Itoa(itemID), w, r, isJs) } -//routePanelThemesMenuItemDeleteSubmit func ThemesMenuItemDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User, sitemID string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { @@ -301,7 +293,6 @@ func ThemesMenuItemDeleteSubmit(w http.ResponseWriter, r *http.Request, user com return successRedirect("/panel/themes/menus/", w, r, isJs) } -//routePanelThemesMenuItemOrderSubmit func ThemesMenuItemOrderSubmit(w http.ResponseWriter, r *http.Request, user common.User, smid string) common.RouteError { _, ferr := common.SimplePanelUserCheck(w, r, &user) if ferr != nil { diff --git a/routes/panel/users.go b/routes/panel/users.go index 1aeab43d..8b257cc9 100644 --- a/routes/panel/users.go +++ b/routes/panel/users.go @@ -5,7 +5,7 @@ import ( "net/http" "strconv" - "../../common" + "github.com/Azareal/Gosora/common" ) func Users(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/panel/word_filters.go b/routes/panel/word_filters.go index acc774fa..81c2faae 100644 --- a/routes/panel/word_filters.go +++ b/routes/panel/word_filters.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "../../common" + "github.com/Azareal/Gosora/common" ) func WordFilters(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/poll.go b/routes/poll.go index a37e5714..71f915bc 100644 --- a/routes/poll.go +++ b/routes/poll.go @@ -7,8 +7,8 @@ import ( "net/http" "strconv" - "../common" - "../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) func PollVote(w http.ResponseWriter, r *http.Request, user common.User, sPollID string) common.RouteError { diff --git a/routes/profile.go b/routes/profile.go index 682c7840..b60b2124 100644 --- a/routes/profile.go +++ b/routes/profile.go @@ -7,8 +7,8 @@ import ( "strings" "time" - "../common" - "../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/query_gen" ) type ProfileStmts struct { diff --git a/routes/reply.go b/routes/reply.go index 14d277d0..5c62198b 100644 --- a/routes/reply.go +++ b/routes/reply.go @@ -12,8 +12,8 @@ import ( "strconv" "strings" - "../common" - "../common/counters" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/common/counters" ) // TODO: De-duplicate the upload logic diff --git a/routes/reports.go b/routes/reports.go index 0f2910a6..aed09c6c 100644 --- a/routes/reports.go +++ b/routes/reports.go @@ -5,8 +5,8 @@ import ( "net/http" "strconv" - "../common" - "../common/counters" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/common/counters" ) func ReportSubmit(w http.ResponseWriter, r *http.Request, user common.User, sitemID string) common.RouteError { diff --git a/routes/topic.go b/routes/topic.go index 9a670aa4..aa17e2ce 100644 --- a/routes/topic.go +++ b/routes/topic.go @@ -13,9 +13,9 @@ import ( "strconv" "strings" - "../common" - "../common/counters" - "../query_gen/lib" + "github.com/Azareal/Gosora/common" + "github.com/Azareal/Gosora/common/counters" + "github.com/Azareal/Gosora/query_gen" ) type TopicStmts struct { @@ -218,16 +218,10 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, urlBit } } - if common.RunPreRenderHook("pre_render_view_topic", w, r, &user, &tpage) { - return nil - } - err = common.RunThemeTemplate(header.Theme.Name, "topic", tpage, w) - if err != nil { - return common.InternalError(err, w, r) - } + rerr := renderTemplate("topic", w, r, header, tpage) counters.TopicViewCounter.Bump(topic.ID) // TODO: Move this into the router? counters.ForumViewCounter.Bump(topic.ParentID) - return nil + return rerr } // ? - Should we add a new permission or permission zone (like per-forum permissions) specifically for profile comment creation @@ -304,15 +298,7 @@ func CreateTopic(w http.ResponseWriter, r *http.Request, user common.User, sfid } ctpage := common.CreateTopicPage{header, forumList, fid} - if common.RunPreRenderHook("pre_render_create_topic", w, r, &user, &ctpage) { - return nil - } - - err = common.RunThemeTemplate(header.Theme.Name, "create_topic", ctpage, w) - if err != nil { - return common.InternalError(err, w, r) - } - return nil + return renderTemplate("create_topic", w, r, header, ctpage) } func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { @@ -877,7 +863,6 @@ func LikeTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s score := 1 err = topic.Like(score, user.ID) - //log.Print("likeErr: ", err) if err == common.ErrAlreadyLiked { return common.LocalErrorJSQ("You already liked this", w, r, user, isJs) } else if err != nil { diff --git a/routes/topic_list.go b/routes/topic_list.go index 68532f1e..57547997 100644 --- a/routes/topic_list.go +++ b/routes/topic_list.go @@ -5,7 +5,7 @@ import ( "net/http" "strconv" - "../common" + "github.com/Azareal/Gosora/common" ) func TopicList(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { diff --git a/routes/user.go b/routes/user.go index f8eb94d1..28ee7dcb 100644 --- a/routes/user.go +++ b/routes/user.go @@ -6,7 +6,7 @@ import ( "strconv" "time" - "../common" + "github.com/Azareal/Gosora/common" ) func BanUserSubmit(w http.ResponseWriter, r *http.Request, user common.User, suid string) common.RouteError { diff --git a/run-linux b/run-linux index 262354c6..1bef3906 100644 --- a/run-linux +++ b/run-linux @@ -16,10 +16,10 @@ echo "Running the router generator" ./RouterGen echo "Building the query generator" -cd ./query_gen +cd ./cmd/query_gen go build -o QueryGen -mv ./QueryGen .. -cd .. +mv ./QueryGen ../.. +cd ../.. echo "Running the query generator" ./QueryGen diff --git a/run-linux-nowebsockets b/run-linux-nowebsockets index cb3a3a6e..d713d08f 100644 --- a/run-linux-nowebsockets +++ b/run-linux-nowebsockets @@ -16,10 +16,10 @@ echo "Running the router generator" ./RouterGen echo "Building the query generator" -cd ./query_gen +cd ./cmd/query_gen go build -o QueryGen -mv ./QueryGen .. -cd .. +mv ./QueryGen ../.. +cd ../.. echo "Running the query generator" ./QueryGen diff --git a/run-nowebsockets.bat b/run-nowebsockets.bat index d3453350..5043ac4d 100644 --- a/run-nowebsockets.bat +++ b/run-nowebsockets.bat @@ -28,7 +28,7 @@ if %errorlevel% neq 0 ( ) echo Building the query generator -go build ./query_gen +go build "./cmd/query_gen" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/run.bat b/run.bat index 8f173b2b..5b541ad7 100644 --- a/run.bat +++ b/run.bat @@ -28,7 +28,7 @@ if %errorlevel% neq 0 ( ) echo Building the query generator -go build ./query_gen +go build "./cmd/query_gen" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/run_mssql.bat b/run_mssql.bat index 95e502bd..81e8ebcd 100644 --- a/run_mssql.bat +++ b/run_mssql.bat @@ -28,7 +28,7 @@ if %errorlevel% neq 0 ( ) echo Building the query generator -go build ./query_gen +go build "./cmd/query_gen" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/run_tests.bat b/run_tests.bat index c26d6e7a..49d48f23 100644 --- a/run_tests.bat +++ b/run_tests.bat @@ -28,7 +28,7 @@ if %errorlevel% neq 0 ( ) echo Building the query generator -go build ./query_gen +go build "./cmd/query_gen" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/run_tests_mssql.bat b/run_tests_mssql.bat index 18eef5f9..3d9753a4 100644 --- a/run_tests_mssql.bat +++ b/run_tests_mssql.bat @@ -28,7 +28,7 @@ if %errorlevel% neq 0 ( ) echo Building the query generator -go build ./query_gen +go build "./cmd/query_gen" if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/schema/schema.json b/schema/schema.json index ca0fa0d6..b3d1f1d4 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -1,6 +1,6 @@ { - "DBVersion":"8", + "DBVersion":"9", "DynamicFileVersion":"0", - "MinGoVersion":"1.10", + "MinGoVersion":"1.11", "MinVersion":"" } \ No newline at end of file diff --git a/templates/account.html b/templates/account.html new file mode 100644 index 00000000..627c83e1 --- /dev/null +++ b/templates/account.html @@ -0,0 +1,6 @@ +{{template "header.html" . }} +
+ {{template "account_menu.html" . }} +
{{dyntmpl .TmplName . .Header}}
+
+{{template "footer.html" . }} \ No newline at end of file diff --git a/templates/account_own_edit.html b/templates/account_own_edit.html index 0961f254..4c7b3074 100644 --- a/templates/account_own_edit.html +++ b/templates/account_own_edit.html @@ -1,8 +1,4 @@ -{{template "header.html" . }} -
- {{template "account_menu.html" . }} -
-
+
@@ -30,7 +26,4 @@
-
- - -{{template "footer.html" . }} + \ No newline at end of file diff --git a/templates/header.html b/templates/header.html index 30a29adc..b7035596 100644 --- a/templates/header.html +++ b/templates/header.html @@ -45,7 +45,7 @@
{{.CurrentUser.Name}} - No new alerts + {{lang "alerts_no_new_alerts"}}
{{end}} diff --git a/themes/nox/public/account.css b/themes/nox/public/account.css index 8bfe94a8..e37266d0 100644 --- a/themes/nox/public/account.css +++ b/themes/nox/public/account.css @@ -11,11 +11,12 @@ margin-left: 16px; } .colstack_left { - width: 25%; + width: 200px; padding-top: 12px; padding-right: 24px; padding-bottom: 24px; padding-left: 24px; + background-color: #3e3e3e; } .colstack_left .colstack_head { font-size: 19px; @@ -36,7 +37,7 @@ } .colstack_right { - background-color: #444444; + background-color: #333333; width: 75%; padding-right: 24px; padding-bottom: 24px; @@ -47,42 +48,6 @@ } .colstack_right .colstack_head h1 { font-size: 21px; - color: #BBBBBB; -} -.colstack_right .colstack_item.the_form { - background-color: #555555; -} -.colstack_right .colstack_item:not(.colstack_head):not(.rowhead) .rowitem { - background-color: #555555; -} - -input, select, textarea { - background: rgb(107,107,107); - color: rgb(217,217,217); -} -input:focus, select:focus, textarea:focus { - outline: 1px solid rgb(137,137,137); -} - -/* ? - The background properties need to be redeclared for the new image or it won't work properly */ -input { - background-image: url(./fa-svg/pencil-alt-light.svg); - background-size: 12px; - background-repeat: no-repeat; - background-position: right 10px bottom 9px; - background-position-x: right 10px; -} -input::placeholder, textarea::placeholder { - color: rgb(167,167,167); - opacity: 1; /* Firefox fix */ -} -button, .formbutton { - background: rgb(100,100,200); -} - -#themeSelector select { - background: rgb(90,90,90); - color: rgb(200,200,200); } .footer .widget, #poweredByHolder { background-color: #393939; @@ -105,7 +70,7 @@ button, .formbutton { } #dash_left { border-radius: 3px; - background-color: #555555; + background-color: #444444; padding: 12px; height: 180px; width: 240px; @@ -119,7 +84,6 @@ button, .formbutton { margin-left: auto; margin-right: auto; margin-bottom: 8px; - /*font-size: 16px;*/ width: 100px; display: relative; padding-left: 16px; @@ -156,9 +120,9 @@ button, .formbutton { } #dash_right .rowitem { border-radius: 3px; - background-color: #555555; + background-color: #444444; padding: 16px; } #dash_right .rowitem:not(:last-child) { margin-bottom: 8px; -} \ No newline at end of file +} diff --git a/themes/nox/public/panel.css b/themes/nox/public/panel.css index c946199e..b368bccd 100644 --- a/themes/nox/public/panel.css +++ b/themes/nox/public/panel.css @@ -19,11 +19,12 @@ } .colstack_left { - width: 25%; + width: 200px; padding-top: 12px; padding-right: 24px; padding-bottom: 24px; padding-left: 24px; + background-color: #3e3e3e; } .colstack_left .colstack_head { font-size: 19px; @@ -47,7 +48,7 @@ } .colstack_right { - background-color: #444444; + background-color: #333333; width: 75%; padding-top: 12px; padding-right: 24px; @@ -59,13 +60,9 @@ } .colstack_right .colstack_head h1 { font-size: 21px; - color: #BBBBBB; } -.colstack_right .colstack_item.the_form { - background-color: #555555; -} -.colstack_right .colstack_item:not(.colstack_head):not(.rowhead) .rowitem { - background-color: #555555; +.colstack_right .colstack_item.the_form, .colstack_right .colstack_item:not(.colstack_head):not(.rowhead) .rowitem { + background-color: #444444; } .rowitem { display: flex; @@ -79,7 +76,7 @@ .grid_item { border-radius: 3px; color: rgb(190,190,190); - background-color: #555555; + background-color: #444444; padding: 12px; } @@ -87,10 +84,6 @@ margin-left: auto; } -input, select, textarea { - background: rgb(107,107,107); - color: rgb(197,197,197); -} .colstack_right input, .colstack_right select, .colstack_right textarea { padding: 4px; padding-bottom: 3px; @@ -102,35 +95,12 @@ input, select, textarea { padding-right: 6px; } -input:focus, select:focus, textarea:focus { - outline: 1px solid rgb(137,137,137); - color: rgb(207,207,207); -} -/* ? - The background properties need to be redeclared for the new image or it won't work properly */ -input { - background-image: url(./fa-svg/pencil-alt-light.svg); - background-size: 12px; - background-repeat: no-repeat; - background-position: right 9px bottom 7px; - background-position-x: right 9px; -} -input::placeholder, textarea::placeholder { - color: rgb(167,167,167); - opacity: 1; /* Firefox fix */ -} -button, .formbutton { - /*background: rgb(110,110,210); - color: rgb(250,250,250);*/ -} button, .formbutton, .panel_right_button:not(.has_inner_button), #panel_users .profile_url { background: rgb(100,100,200); } #panel_users .panel_tag:not(.panel_right_button) { background: rgb(50,150,50); } -/*.formlabel { - font-size: 17px; -}*/ .panel_right_button:not(.has_inner_button), #panel_users .panel_tag:not(.panel_right_button), #panel_users .profile_url { margin-left: 2px; padding: 5px; @@ -149,13 +119,13 @@ button, .formbutton, .panel_right_button:not(.has_inner_button), #panel_users .p .delete_button:after { content: "{{index .Phrases "panel_delete_button_text"}}"; } -#themeSelector select { +/*#themeSelector select { background: rgb(90,90,90); color: rgb(200,200,200); -} +}*/ .colstack_graph_holder { - background-color: #555555; + background-color: #444444; border-radius: 3px; padding: 16px; padding-bottom: 0px; @@ -237,8 +207,4 @@ button, .formbutton, .panel_right_button:not(.has_inner_button), #panel_users .p #panel_debug .grid_stat:not(.grid_stat_head) { margin-bottom: 5px; -} - -.pageitem { - background-color: #555555; -} +} \ No newline at end of file diff --git a/tickloop.go b/tickloop.go index d5ced549..3a798633 100644 --- a/tickloop.go +++ b/tickloop.go @@ -6,7 +6,7 @@ import ( "sync/atomic" "time" - "./common" + "github.com/Azareal/Gosora/common" ) // TODO: Name the tasks so we can figure out which one it was when something goes wrong? Or maybe toss it up WithStack down there?