Finish porting panel
This commit is contained in:
parent
bc3fa195c1
commit
208bdc03f3
@ -1 +0,0 @@
|
|||||||
package database
|
|
@ -20,21 +20,24 @@ func LogsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
if utils.IsLoggedIn(store) {
|
if utils.IsLoggedIn(store) {
|
||||||
userIdStr := store.Get("userid").(string)
|
userIdStr := store.Get("userid").(string)
|
||||||
userId, err := utils.GetUserId(store); if err != nil {
|
userId, err := utils.GetUserId(store)
|
||||||
|
if err != nil {
|
||||||
ctx.String(500, err.Error())
|
ctx.String(500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the guild exists
|
// Verify the guild exists
|
||||||
guildIdStr := ctx.Param("id")
|
guildIdStr := ctx.Param("id")
|
||||||
guildId, err := strconv.ParseInt(guildIdStr, 10, 64); if err != nil {
|
guildId, err := strconv.ParseInt(guildIdStr, 10, 64)
|
||||||
|
if err != nil {
|
||||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pageStr := ctx.Param("page")
|
pageStr := ctx.Param("page")
|
||||||
page := 1
|
page := 1
|
||||||
i, err := strconv.Atoi(pageStr); if err == nil {
|
i, err := strconv.Atoi(pageStr)
|
||||||
|
if err == nil {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
page = i
|
page = i
|
||||||
}
|
}
|
||||||
@ -55,11 +58,51 @@ func LogsHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageLimit := 30
|
||||||
|
|
||||||
|
// Get logs
|
||||||
|
// Get user ID from URL
|
||||||
|
var filteredUserId int64
|
||||||
|
if utils.IsInt(ctx.Query("userid")) {
|
||||||
|
filteredUserId, _ = strconv.ParseInt(ctx.Query("userid"), 10, 64)
|
||||||
|
}
|
||||||
|
|
||||||
utils.Respond(ctx, template.TemplateSettings.Render(map[string]interface{}{
|
// Get ticket ID from URL
|
||||||
|
var ticketId int
|
||||||
|
if utils.IsInt(ctx.Query("ticketid")) {
|
||||||
|
ticketId, _ = strconv.Atoi(ctx.Query("ticketid"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get username from URL
|
||||||
|
username := ctx.Query("username")
|
||||||
|
|
||||||
|
// Get logs from DB
|
||||||
|
logs := table.GetFilteredTicketArchives(guildId, filteredUserId, username, ticketId)
|
||||||
|
|
||||||
|
// Select 30 logs + format them
|
||||||
|
var formattedLogs []map[string]interface{}
|
||||||
|
for i := (page - 1) * pageLimit; i < (page - 1) * pageLimit + pageLimit; i++ {
|
||||||
|
if i >= len(logs) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
log := logs[i]
|
||||||
|
formattedLogs = append(formattedLogs, map[string]interface{}{
|
||||||
|
"ticketid": log.TicketId,
|
||||||
|
"userid": log.User,
|
||||||
|
"username": log.Username,
|
||||||
|
"uuid": log.Uuid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.Respond(ctx, template.TemplateLogs.Render(map[string]interface{}{
|
||||||
"name": store.Get("name").(string),
|
"name": store.Get("name").(string),
|
||||||
"guildId": guildIdStr,
|
"guildId": guildIdStr,
|
||||||
|
"baseUrl": config.Conf.Server.BaseUrl,
|
||||||
|
"isPageOne": page == 1,
|
||||||
|
"previousPage": page - 1,
|
||||||
|
"nextPage": page + 1,
|
||||||
|
"logs": formattedLogs,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
ctx.Redirect(302, "/login")
|
ctx.Redirect(302, "/login")
|
||||||
|
@ -3,6 +3,7 @@ package manage
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/TicketsBot/GoPanel/app/http/template"
|
"github.com/TicketsBot/GoPanel/app/http/template"
|
||||||
"github.com/TicketsBot/GoPanel/config"
|
"github.com/TicketsBot/GoPanel/config"
|
||||||
"github.com/TicketsBot/GoPanel/database/table"
|
"github.com/TicketsBot/GoPanel/database/table"
|
||||||
@ -24,14 +25,16 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
if utils.IsLoggedIn(store) {
|
if utils.IsLoggedIn(store) {
|
||||||
userIdStr := store.Get("userid").(string)
|
userIdStr := store.Get("userid").(string)
|
||||||
userId, err := utils.GetUserId(store); if err != nil {
|
userId, err := utils.GetUserId(store)
|
||||||
|
if err != nil {
|
||||||
ctx.String(500, err.Error())
|
ctx.String(500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the guild exists
|
// Verify the guild exists
|
||||||
guildIdStr := ctx.Param("id")
|
guildIdStr := ctx.Param("id")
|
||||||
guildId, err := strconv.ParseInt(guildIdStr, 10, 64); if err != nil {
|
guildId, err := strconv.ParseInt(guildIdStr, 10, 64)
|
||||||
|
if err != nil {
|
||||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -83,11 +86,8 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
table.UpdateTicketLimit(guildId, limit)
|
table.UpdateTicketLimit(guildId, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a list of actual category IDs
|
|
||||||
categories := guild.GetCategories()
|
|
||||||
|
|
||||||
// /users/@me/guilds doesn't return channels, so we have to get them for the specific guild
|
// /users/@me/guilds doesn't return channels, so we have to get them for the specific guild
|
||||||
if len(categories) == 0 {
|
if len(guild.Channels) == 0 {
|
||||||
var channels []objects.Channel
|
var channels []objects.Channel
|
||||||
endpoint := guildendpoint.GetGuildChannels(int(guildId))
|
endpoint := guildendpoint.GetGuildChannels(int(guildId))
|
||||||
err = endpoint.Request(store, nil, nil, &channels)
|
err = endpoint.Request(store, nil, nil, &channels)
|
||||||
@ -96,7 +96,6 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
// Not in guild
|
// Not in guild
|
||||||
} else {
|
} else {
|
||||||
guild.Channels = channels
|
guild.Channels = channels
|
||||||
categories = guild.GetCategories()
|
|
||||||
|
|
||||||
// Update cache of categories now that we have them
|
// Update cache of categories now that we have them
|
||||||
guilds := table.GetGuilds(userIdStr)
|
guilds := table.GetGuilds(userIdStr)
|
||||||
@ -117,7 +116,8 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
// Insert updated guild
|
// Insert updated guild
|
||||||
guilds = utils.Insert(guilds, index, guild)
|
guilds = utils.Insert(guilds, index, guild)
|
||||||
|
|
||||||
marshalled, err := json.Marshal(guilds); if err != nil {
|
marshalled, err := json.Marshal(guilds)
|
||||||
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
} else {
|
} else {
|
||||||
table.UpdateGuilds(userIdStr, base64.StdEncoding.EncodeToString(marshalled))
|
table.UpdateGuilds(userIdStr, base64.StdEncoding.EncodeToString(marshalled))
|
||||||
@ -126,6 +126,10 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a list of actual category IDs
|
||||||
|
categories := guild.GetCategories()
|
||||||
|
|
||||||
|
// Convert to category IDs
|
||||||
var categoryIds []string
|
var categoryIds []string
|
||||||
for _, c := range categories {
|
for _, c := range categories {
|
||||||
categoryIds = append(categoryIds, c.Id)
|
categoryIds = append(categoryIds, c.Id)
|
||||||
@ -155,6 +159,43 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Archive channel
|
||||||
|
// Create a list of IDs
|
||||||
|
var channelIds []string
|
||||||
|
for _, c := range guild.Channels {
|
||||||
|
channelIds = append(channelIds, c.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update or get current archive channel if blank or invalid
|
||||||
|
var archiveChannel int64
|
||||||
|
archiveChannelStr := ctx.Query("archivechannel")
|
||||||
|
|
||||||
|
// Verify category ID is an int and set default category ID
|
||||||
|
if utils.IsInt(archiveChannelStr) {
|
||||||
|
archiveChannel, _ = strconv.ParseInt(archiveChannelStr, 10, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
if archiveChannelStr == "" || !utils.IsInt(archiveChannelStr) || !utils.Contains(channelIds, archiveChannelStr) {
|
||||||
|
archiveChannel = table.GetArchiveChannel(guildId)
|
||||||
|
} else {
|
||||||
|
table.UpdateArchiveChannel(guildId, archiveChannel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format channels for templating
|
||||||
|
var formattedChannels []map[string]interface{}
|
||||||
|
for _, c := range guild.Channels {
|
||||||
|
if c.Id == strconv.Itoa(int(archiveChannel)) {
|
||||||
|
fmt.Println(c.Name)
|
||||||
|
}
|
||||||
|
if c.Type == 0 {
|
||||||
|
formattedChannels = append(formattedChannels, map[string]interface{}{
|
||||||
|
"channelid": c.Id,
|
||||||
|
"channelname": c.Name,
|
||||||
|
"active": c.Id == strconv.Itoa(int(archiveChannel)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
utils.Respond(ctx, template.TemplateSettings.Render(map[string]interface{}{
|
utils.Respond(ctx, template.TemplateSettings.Render(map[string]interface{}{
|
||||||
"name": store.Get("name").(string),
|
"name": store.Get("name").(string),
|
||||||
"guildId": guildIdStr,
|
"guildId": guildIdStr,
|
||||||
@ -162,6 +203,7 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
"welcomeMessage": welcomeMessage,
|
"welcomeMessage": welcomeMessage,
|
||||||
"ticketLimit": limit,
|
"ticketLimit": limit,
|
||||||
"categories": formattedCategories,
|
"categories": formattedCategories,
|
||||||
|
"channels": formattedChannels,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
ctx.Redirect(302, "/login")
|
ctx.Redirect(302, "/login")
|
||||||
|
84
app/http/endpoints/manage/viewlog.go
Normal file
84
app/http/endpoints/manage/viewlog.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package manage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/TicketsBot/GoPanel/config"
|
||||||
|
"github.com/TicketsBot/GoPanel/database/table"
|
||||||
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
|
"github.com/TicketsBot/GoPanel/utils/discord/objects"
|
||||||
|
"github.com/gin-gonic/contrib/sessions"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LogViewHandler(ctx *gin.Context) {
|
||||||
|
store := sessions.Default(ctx)
|
||||||
|
if store == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer store.Save()
|
||||||
|
|
||||||
|
if utils.IsLoggedIn(store) {
|
||||||
|
userIdStr := store.Get("userid").(string)
|
||||||
|
userId, err := utils.GetUserId(store)
|
||||||
|
if err != nil {
|
||||||
|
ctx.String(500, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the guild exists
|
||||||
|
guildIdStr := ctx.Param("id")
|
||||||
|
guildId, err := strconv.ParseInt(guildIdStr, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get object for selected guild
|
||||||
|
var guild objects.Guild
|
||||||
|
for _, g := range table.GetGuilds(userIdStr) {
|
||||||
|
if g.Id == guildIdStr {
|
||||||
|
guild = g
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the user has permissions to be here
|
||||||
|
if !guild.Owner && !table.IsAdmin(guildId, userId) {
|
||||||
|
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid := ctx.Param("uuid")
|
||||||
|
cdnUrl := table.GetCdnUrl(guildId, uuid)
|
||||||
|
|
||||||
|
if cdnUrl == "" {
|
||||||
|
ctx.Redirect(302, fmt.Sprintf("/manage/%s/logs/page/1", guild.Id))
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
req, err := http.NewRequest("GET", cdnUrl, nil); if err != nil {
|
||||||
|
ctx.String(500, fmt.Sprintf("Failed to read log: %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
client.Timeout = 3 * time.Second
|
||||||
|
|
||||||
|
res, err := client.Do(req); if err != nil {
|
||||||
|
ctx.String(500, fmt.Sprintf("Failed to read log: %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
content, err := ioutil.ReadAll(res.Body); if err != nil {
|
||||||
|
ctx.String(500, fmt.Sprintf("Failed to read log: %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.String(200, string(content))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type(
|
type (
|
||||||
TokenData struct {
|
TokenData struct {
|
||||||
ClientId string `qs:"client_id"`
|
ClientId string `qs:"client_id"`
|
||||||
ClientSecret string `qs:"client_secret"`
|
ClientSecret string `qs:"client_secret"`
|
||||||
@ -52,17 +52,19 @@ func CallbackHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := discord.AccessToken(code); if err != nil {
|
res, err := discord.AccessToken(code)
|
||||||
|
if err != nil {
|
||||||
ctx.String(500, err.Error())
|
ctx.String(500, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
store.Set("access_token", res.AccessToken)
|
store.Set("access_token", res.AccessToken)
|
||||||
store.Set("refresh_token", res.RefreshToken)
|
store.Set("refresh_token", res.RefreshToken)
|
||||||
store.Set("expiry", (time.Now().UnixNano() / int64(time.Second)) + int64(res.ExpiresIn))
|
store.Set("expiry", (time.Now().UnixNano()/int64(time.Second))+int64(res.ExpiresIn))
|
||||||
|
|
||||||
// Get ID + name
|
// Get ID + name
|
||||||
var currentUser objects.User
|
var currentUser objects.User
|
||||||
err = user.CurrentUser.Request(store, nil, nil, ¤tUser); if err != nil {
|
err = user.CurrentUser.Request(store, nil, nil, ¤tUser)
|
||||||
|
if err != nil {
|
||||||
ctx.String(500, err.Error())
|
ctx.String(500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -73,17 +75,19 @@ func CallbackHandler(ctx *gin.Context) {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Redirect(302,config.Conf.Server.BaseUrl)
|
ctx.Redirect(302, config.Conf.Server.BaseUrl)
|
||||||
|
|
||||||
// Cache guilds because Discord takes like 2 whole seconds to return then
|
// Cache guilds because Discord takes like 2 whole seconds to return then
|
||||||
go func() {
|
go func() {
|
||||||
var guilds []objects.Guild
|
var guilds []objects.Guild
|
||||||
err = user.CurrentUserGuilds.Request(store, nil, nil, &guilds); if err != nil {
|
err = user.CurrentUserGuilds.Request(store, nil, nil, &guilds)
|
||||||
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
marshalled, err := json.Marshal(guilds); if err != nil {
|
marshalled, err := json.Marshal(guilds)
|
||||||
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,8 @@ func IndexHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
if utils.IsLoggedIn(store) {
|
if utils.IsLoggedIn(store) {
|
||||||
userIdStr := store.Get("userid").(string)
|
userIdStr := store.Get("userid").(string)
|
||||||
userId, err := utils.GetUserId(store); if err != nil {
|
userId, err := utils.GetUserId(store)
|
||||||
|
if err != nil {
|
||||||
ctx.String(500, err.Error())
|
ctx.String(500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -28,7 +29,8 @@ func IndexHandler(ctx *gin.Context) {
|
|||||||
adminGuilds := make([]objects.Guild, 0)
|
adminGuilds := make([]objects.Guild, 0)
|
||||||
adminGuildIds := table.GetAdminGuilds(userId)
|
adminGuildIds := table.GetAdminGuilds(userId)
|
||||||
for _, guild := range table.GetGuilds(userIdStr) {
|
for _, guild := range table.GetGuilds(userIdStr) {
|
||||||
guildId, err := strconv.ParseInt(guild.Id, 10, 64); if err != nil {
|
guildId, err := strconv.ParseInt(guild.Id, 10, 64)
|
||||||
|
if err != nil {
|
||||||
ctx.String(500, err.Error())
|
ctx.String(500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -58,4 +60,3 @@ func IndexHandler(ctx *gin.Context) {
|
|||||||
ctx.Redirect(302, "/login")
|
ctx.Redirect(302, "/login")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,9 @@ func StartServer() {
|
|||||||
// /manage/:id/logs/page/:page
|
// /manage/:id/logs/page/:page
|
||||||
router.GET("/manage/:id/logs/page/:page", manage.LogsHandler)
|
router.GET("/manage/:id/logs/page/:page", manage.LogsHandler)
|
||||||
|
|
||||||
|
// /manage/:id/logs/view/:uuid
|
||||||
|
router.GET("/manage/:id/logs/view/:uuid", manage.LogViewHandler)
|
||||||
|
|
||||||
if err := router.Run(config.Conf.Server.Host); err != nil {
|
if err := router.Run(config.Conf.Server.Host); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ type Template struct {
|
|||||||
Layout Layout
|
Layout Layout
|
||||||
}
|
}
|
||||||
|
|
||||||
var(
|
var (
|
||||||
LayoutMain Layout
|
LayoutMain Layout
|
||||||
|
|
||||||
TemplateIndex Template
|
TemplateIndex Template
|
||||||
@ -48,7 +48,8 @@ func LoadTemplates() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadLayout(name string) *mustache.Template {
|
func loadLayout(name string) *mustache.Template {
|
||||||
tmpl, err := mustache.ParseFile(fmt.Sprintf("./public/templates/layouts/%s.mustache", name)); if err != nil {
|
tmpl, err := mustache.ParseFile(fmt.Sprintf("./public/templates/layouts/%s.mustache", name))
|
||||||
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +57,8 @@ func loadLayout(name string) *mustache.Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadTemplate(name string) *mustache.Template {
|
func loadTemplate(name string) *mustache.Template {
|
||||||
tmpl, err := mustache.ParseFile(fmt.Sprintf("./public/templates/views/%s.mustache", name)); if err != nil {
|
tmpl, err := mustache.ParseFile(fmt.Sprintf("./public/templates/views/%s.mustache", name))
|
||||||
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type(
|
type (
|
||||||
Config struct {
|
Config struct {
|
||||||
Server Server
|
Server Server
|
||||||
Oauth Oauth
|
Oauth Oauth
|
||||||
@ -58,16 +58,18 @@ type(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var(
|
var (
|
||||||
Conf Config
|
Conf Config
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadConfig() {
|
func LoadConfig() {
|
||||||
raw, err := ioutil.ReadFile("config.toml"); if err != nil {
|
raw, err := ioutil.ReadFile("config.toml")
|
||||||
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = toml.Decode(string(raw), &Conf); if err != nil {
|
_, err = toml.Decode(string(raw), &Conf)
|
||||||
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var(
|
var (
|
||||||
Database gorm.DB
|
Database gorm.DB
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,7 +20,8 @@ func ConnectToDatabase() {
|
|||||||
config.Conf.MariaDB.Database,
|
config.Conf.MariaDB.Database,
|
||||||
)
|
)
|
||||||
|
|
||||||
db, err := gorm.Open("mysql", uri); if err != nil {
|
db, err := gorm.Open("mysql", uri)
|
||||||
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
database/table/archivechannel.go
Normal file
29
database/table/archivechannel.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package table
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/TicketsBot/GoPanel/database"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ArchiveChannel struct {
|
||||||
|
Guild int64 `gorm:"column:GUILDID"`
|
||||||
|
Channel int64 `gorm:"column:CHANNELID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ArchiveChannel) TableName() string {
|
||||||
|
return "archivechannel"
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateArchiveChannel(guildId int64, channelId int64) {
|
||||||
|
fmt.Println(channelId)
|
||||||
|
var channel ArchiveChannel
|
||||||
|
database.Database.Where(ArchiveChannel{Guild: guildId}).Assign(ArchiveChannel{Channel: channelId}).FirstOrCreate(&channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetArchiveChannel(guildId int64) int64 {
|
||||||
|
var channel ArchiveChannel
|
||||||
|
database.Database.Where(&ArchiveChannel{Guild: guildId}).First(&channel)
|
||||||
|
|
||||||
|
return channel.Channel
|
||||||
|
}
|
||||||
|
|
@ -24,7 +24,8 @@ func UpdateGuilds(userId string, guilds string) {
|
|||||||
func GetGuilds(userId string) []objects.Guild {
|
func GetGuilds(userId string) []objects.Guild {
|
||||||
var cache GuildCache
|
var cache GuildCache
|
||||||
database.Database.Where(&GuildCache{UserId: userId}).First(&cache)
|
database.Database.Where(&GuildCache{UserId: userId}).First(&cache)
|
||||||
decoded, err := base64.StdEncoding.DecodeString(cache.Guilds); if err != nil {
|
decoded, err := base64.StdEncoding.DecodeString(cache.Guilds)
|
||||||
|
if err != nil {
|
||||||
return make([]objects.Guild, 0)
|
return make([]objects.Guild, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ func UpdatePrefix(guildId int64, prefix string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetPrefix(guildId int64) string {
|
func GetPrefix(guildId int64) string {
|
||||||
prefix := Prefix{Prefix:"t!"}
|
prefix := Prefix{Prefix: "t!"}
|
||||||
database.Database.Where(&Prefix{GuildId: guildId}).First(&prefix)
|
database.Database.Where(&Prefix{GuildId: guildId}).First(&prefix)
|
||||||
|
|
||||||
return prefix.Prefix
|
return prefix.Prefix
|
||||||
|
@ -19,7 +19,7 @@ func (TicketArchive) TableName() string {
|
|||||||
|
|
||||||
func GetTicketArchives(guildId int64) []TicketArchive {
|
func GetTicketArchives(guildId int64) []TicketArchive {
|
||||||
var archives []TicketArchive
|
var archives []TicketArchive
|
||||||
database.Database.Where(&TicketArchive{Guild: guildId}).Find(&archives)
|
database.Database.Where(&TicketArchive{Guild: guildId}).Order("TICKETID desc").Find(&archives)
|
||||||
|
|
||||||
return archives
|
return archives
|
||||||
}
|
}
|
||||||
@ -38,7 +38,13 @@ func GetFilteredTicketArchives(guildId int64, userId int64, username string, tic
|
|||||||
query = query.Where(&TicketArchive{TicketId: ticketId})
|
query = query.Where(&TicketArchive{TicketId: ticketId})
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Find(&archives)
|
query.Order("TICKETID desc").Find(&archives)
|
||||||
|
|
||||||
return archives
|
return archives
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetCdnUrl(guildId int64, uuid string) string {
|
||||||
|
var archive TicketArchive
|
||||||
|
database.Database.Where(&TicketArchive{Guild: guildId, Uuid: uuid}).First(&archive)
|
||||||
|
return archive.CdnUrl
|
||||||
|
}
|
||||||
|
@ -18,7 +18,7 @@ func UpdateWelcomeMessage(guildId int64, message string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetWelcomeMessage(guildId int64) string {
|
func GetWelcomeMessage(guildId int64) string {
|
||||||
message := WelcomeMessage{Message:"No message specified"}
|
message := WelcomeMessage{Message: "No message specified"}
|
||||||
database.Database.Where(&WelcomeMessage{GuildId: guildId}).First(&message)
|
database.Database.Where(&WelcomeMessage{GuildId: guildId}).First(&message)
|
||||||
|
|
||||||
return message.Message
|
return message.Message
|
||||||
|
@ -60,12 +60,11 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#logs}}
|
{{#logs}}
|
||||||
{{{baseUrl}}}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{TICKETID}}</td>
|
<td>{{ticketid}}</td>
|
||||||
<td>{{USERNAME}}</td>
|
<td>{{username}}</td>
|
||||||
<td>{{USERID}}</td>
|
<td>{{userid}}</td>
|
||||||
<td><a href="{{baseUrl}}/logs/{{UUID}}">{{UUID}}</a></td>
|
<td><a href="{{baseUrl}}/manage/{{guildId}}/logs/view/{{uuid}}">{{uuid}}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/logs}}
|
{{/logs}}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -64,6 +64,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="input-field col s12">
|
||||||
|
<p><b>Archive Channel</b></p>
|
||||||
|
<select name="archivechannel">
|
||||||
|
{{#channels}}
|
||||||
|
{{#active}}
|
||||||
|
<option value="{{channelid}}" selected>#{{channelname}}</option>
|
||||||
|
{{/active}}
|
||||||
|
{{^active}}
|
||||||
|
<option value="{{channelid}}">#{{channelname}}</option>
|
||||||
|
{{/active}}
|
||||||
|
{{/channels}}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12 center-align">
|
<div class="col s12 center-align">
|
||||||
<button class="btn waves-effect waves-light indigo darken-1" type="submit" name="action">Save
|
<button class="btn waves-effect waves-light indigo darken-1" type="submit" name="action">Save
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type(
|
type (
|
||||||
TokenData struct {
|
TokenData struct {
|
||||||
ClientId string `qs:"client_id"`
|
ClientId string `qs:"client_id"`
|
||||||
ClientSecret string `qs:"client_secret"`
|
ClientSecret string `qs:"client_secret"`
|
||||||
@ -51,7 +51,8 @@ func AccessToken(code string) (TokenResponse, error) {
|
|||||||
Scope: "identify guilds",
|
Scope: "identify guilds",
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := tokenPost(data); if err != nil {
|
res, err := tokenPost(data)
|
||||||
|
if err != nil {
|
||||||
return TokenResponse{}, err
|
return TokenResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,8 @@ func RefreshToken(refreshToken string) (TokenResponse, error) {
|
|||||||
Scope: "identify guilds",
|
Scope: "identify guilds",
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := tokenPost(data); if err != nil {
|
res, err := tokenPost(data)
|
||||||
|
if err != nil {
|
||||||
return TokenResponse{}, err
|
return TokenResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,12 +88,14 @@ func RefreshToken(refreshToken string) (TokenResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tokenPost(body ...interface{}) ([]byte, error) {
|
func tokenPost(body ...interface{}) ([]byte, error) {
|
||||||
str, err := qs.Marshal(body[0]); if err != nil {
|
str, err := qs.Marshal(body[0])
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
encoded := []byte(str)
|
encoded := []byte(str)
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", TokenEndpoint, bytes.NewBuffer([]byte(encoded))); if err != nil {
|
req, err := http.NewRequest("POST", TokenEndpoint, bytes.NewBuffer([]byte(encoded)))
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,12 +104,14 @@ func tokenPost(body ...interface{}) ([]byte, error) {
|
|||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
client.Timeout = 3 * time.Second
|
client.Timeout = 3 * time.Second
|
||||||
|
|
||||||
res, err := client.Do(req); if err != nil {
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
content, err := ioutil.ReadAll(res.Body); if err != nil {
|
content, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ type RequestType string
|
|||||||
type ContentType string
|
type ContentType string
|
||||||
type AuthorizationType string
|
type AuthorizationType string
|
||||||
|
|
||||||
const(
|
const (
|
||||||
GET RequestType = "GET"
|
GET RequestType = "GET"
|
||||||
POST RequestType = "POST"
|
POST RequestType = "POST"
|
||||||
PATCH RequestType = "PATCH"
|
PATCH RequestType = "PATCH"
|
||||||
@ -48,12 +48,14 @@ func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, bod
|
|||||||
// Encode body
|
// Encode body
|
||||||
var encoded []byte
|
var encoded []byte
|
||||||
if *contentType == ApplicationJson {
|
if *contentType == ApplicationJson {
|
||||||
raw, err := json.Marshal(body); if err != nil {
|
raw, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
encoded = raw
|
encoded = raw
|
||||||
} else if *contentType == ApplicationFormUrlEncoded {
|
} else if *contentType == ApplicationFormUrlEncoded {
|
||||||
str, err := qs.Marshal(body); if err != nil {
|
str, err := qs.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
encoded = []byte(str)
|
encoded = []byte(str)
|
||||||
@ -80,33 +82,38 @@ func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, bod
|
|||||||
|
|
||||||
// Check if needs refresh
|
// Check if needs refresh
|
||||||
if (time.Now().UnixNano() / int64(time.Second)) > int64(expiry) {
|
if (time.Now().UnixNano() / int64(time.Second)) > int64(expiry) {
|
||||||
res, err := RefreshToken(refreshToken); if err != nil {
|
res, err := RefreshToken(refreshToken)
|
||||||
|
if err != nil {
|
||||||
store.Clear()
|
store.Clear()
|
||||||
_ = store.Save()
|
_ = store.Save()
|
||||||
return errors.New("Please login again!")
|
return errors.New("Please login again!")
|
||||||
}
|
}
|
||||||
|
|
||||||
store.Set("access_token", res.AccessToken)
|
store.Set("access_token", res.AccessToken)
|
||||||
store.Set("expiry", (time.Now().UnixNano() / int64(time.Second)) + int64(res.ExpiresIn))
|
store.Set("expiry", (time.Now().UnixNano()/int64(time.Second))+int64(res.ExpiresIn))
|
||||||
store.Set("refresh_token", res.RefreshToken)
|
store.Set("refresh_token", res.RefreshToken)
|
||||||
|
|
||||||
accessToken = res.AccessToken
|
accessToken = res.AccessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
switch e.AuthorizationType{
|
switch e.AuthorizationType {
|
||||||
case BEARER: req.Header.Set("Authorization", "Bearer " + accessToken)
|
case BEARER:
|
||||||
case BOT: req.Header.Set("Authorization", "Bot " + config.Conf.Bot.Token)
|
req.Header.Set("Authorization", "Bearer "+accessToken)
|
||||||
|
case BOT:
|
||||||
|
req.Header.Set("Authorization", "Bot "+config.Conf.Bot.Token)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
client.Timeout = 3 * time.Second
|
client.Timeout = 3 * time.Second
|
||||||
|
|
||||||
res, err := client.Do(req); if err != nil {
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
content, err := ioutil.ReadAll(res.Body); if err != nil {
|
content, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@ package utils
|
|||||||
import "io/ioutil"
|
import "io/ioutil"
|
||||||
|
|
||||||
func ReadFile(path string) (string, error) {
|
func ReadFile(path string) (string, error) {
|
||||||
content, err := ioutil.ReadFile(path); if err != nil {
|
content, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func Contains(s interface{}, elem interface{}) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func Insert(slice []objects.Guild, index int , value objects.Guild) []objects.Guild {
|
func Insert(slice []objects.Guild, index int, value objects.Guild) []objects.Guild {
|
||||||
// Grow the slice by one element.
|
// Grow the slice by one element.
|
||||||
slice = slice[0 : len(slice)+1]
|
slice = slice[0 : len(slice)+1]
|
||||||
// Use copy to move the upper part of the slice out of the way and open a hole.
|
// Use copy to move the upper part of the slice out of the way and open a hole.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user