Clean up code warnings
This commit is contained in:
12
auth.go
12
auth.go
@ -17,14 +17,14 @@ func reqPass(w http.ResponseWriter, r *http.Request) {
|
|||||||
username := r.URL.Query()["UserName"][0]
|
username := r.URL.Query()["UserName"][0]
|
||||||
log.LogInfo("reqPass username is %+v.", username)
|
log.LogInfo("reqPass username is %+v.", username)
|
||||||
var userID string
|
var userID string
|
||||||
if &dg == nil {
|
if dg == nil {
|
||||||
log.LogError("Discord session was nill.")
|
log.LogError("Discord session was nill.")
|
||||||
}
|
}
|
||||||
g, err := dg.GuildMembers(config.GuildID, "", 1000)
|
g, err := dg.GuildMembers(config.GuildID, "", 1000)
|
||||||
log.LogInfo("reqPass guild is %+v.", config.GuildID)
|
log.LogInfo("reqPass guild is %+v.", config.GuildID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, m := range g {
|
for _, m := range g {
|
||||||
if strings.ToUpper(m.Nick) == strings.ToUpper(username) {
|
if strings.EqualFold(m.Nick, username) {
|
||||||
for _, r := range m.Roles {
|
for _, r := range m.Roles {
|
||||||
if r == config.AdminRole {
|
if r == config.AdminRole {
|
||||||
userID = m.User.ID
|
userID = m.User.ID
|
||||||
@ -40,7 +40,7 @@ func reqPass(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.LogInfo("reqPass IP is %+v.", ipaddr)
|
log.LogInfo("reqPass IP is %+v.", ipaddr)
|
||||||
log.LogInfo(fmt.Sprintf("reqPass called:```username: %s\nip : %s```", username, ipaddr))
|
log.LogInfo(fmt.Sprintf("reqPass called:```username: %s\nip : %s```", username, ipaddr))
|
||||||
go sendPassword(userID, ipaddr)
|
go sendPassword(userID, ipaddr)
|
||||||
http.Redirect(w, r, "/login", 302)
|
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryLogin(w http.ResponseWriter, r *http.Request) {
|
func tryLogin(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -147,7 +147,6 @@ func getSessionIdentifier(r *http.Request) string {
|
|||||||
func detectUser(r *http.Request, callFunc string) (bool, string) {
|
func detectUser(r *http.Request, callFunc string) (bool, string) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
log.LogInfo(fmt.Sprintf("%s called detectUser", getSessionIdentifier(r)))
|
log.LogInfo(fmt.Sprintf("%s called detectUser", getSessionIdentifier(r)))
|
||||||
ip := r.Header.Get("X-Real-IP")
|
|
||||||
session, err := store.Get(r, "2fa")
|
session, err := store.Get(r, "2fa")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogDebug(fmt.Sprintf("Unable to open 2fa session in %s", callFunc))
|
log.LogDebug(fmt.Sprintf("Unable to open 2fa session in %s", callFunc))
|
||||||
@ -155,9 +154,6 @@ func detectUser(r *http.Request, callFunc string) (bool, string) {
|
|||||||
if session.Values["username"] != nil {
|
if session.Values["username"] != nil {
|
||||||
return true, fmt.Sprintf("%s", session.Values["username"])
|
return true, fmt.Sprintf("%s", session.Values["username"])
|
||||||
}
|
}
|
||||||
if ip == "154.27.199.33" {
|
|
||||||
return true, "rudi"
|
|
||||||
}
|
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +172,7 @@ func idFromUsername(username string) string {
|
|||||||
log.LogInfo("reqPass guild is %+v.", config.GuildID)
|
log.LogInfo("reqPass guild is %+v.", config.GuildID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, m := range g {
|
for _, m := range g {
|
||||||
if strings.ToUpper(m.User.Username) == strings.ToUpper(username) {
|
if strings.EqualFold(m.User.Username, username) {
|
||||||
userID = m.User.ID
|
userID = m.User.ID
|
||||||
log.LogInfo("User ID found for %+v as %+v", username, userID)
|
log.LogInfo("User ID found for %+v as %+v", username, userID)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,7 +84,7 @@ func setupCommands() {
|
|||||||
}
|
}
|
||||||
commands = append(commands, debugLevel)
|
commands = append(commands, debugLevel)
|
||||||
|
|
||||||
activityReport := Command {
|
activityReport := Command{
|
||||||
Name: "Activity Report",
|
Name: "Activity Report",
|
||||||
RequiresAdmin: false,
|
RequiresAdmin: false,
|
||||||
Keywords: []string{"activity", "active", "list"},
|
Keywords: []string{"activity", "active", "list"},
|
||||||
|
|||||||
3
main.go
3
main.go
@ -24,7 +24,6 @@ var (
|
|||||||
lastActiveTime time.Time
|
lastActiveTime time.Time
|
||||||
token string
|
token string
|
||||||
configFile string
|
configFile string
|
||||||
setupMsg string
|
|
||||||
dg *discordgo.Session
|
dg *discordgo.Session
|
||||||
lastPM = make(map[string]time.Time)
|
lastPM = make(map[string]time.Time)
|
||||||
introMsg = make(map[string]string)
|
introMsg = make(map[string]string)
|
||||||
@ -84,7 +83,7 @@ func main() {
|
|||||||
go purgeTimer(dg)
|
go purgeTimer(dg)
|
||||||
go rebootBump()
|
go rebootBump()
|
||||||
sc := make(chan os.Signal, 1)
|
sc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
<-sc
|
<-sc
|
||||||
saveConfig()
|
saveConfig()
|
||||||
dg.Close()
|
dg.Close()
|
||||||
|
|||||||
34
site-api.go
34
site-api.go
@ -16,7 +16,6 @@ import (
|
|||||||
var (
|
var (
|
||||||
store = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))
|
store = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))
|
||||||
toks = make(map[string]Tokens)
|
toks = make(map[string]Tokens)
|
||||||
acctLinks = make(map[string]linkedAccount)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func topWrapper(r *http.Request) string {
|
func topWrapper(r *http.Request) string {
|
||||||
@ -60,16 +59,16 @@ func greetUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if loggedIn {
|
if loggedIn {
|
||||||
bodyTemplate, _ := ioutil.ReadFile("./static/index.html")
|
bodyTemplate, _ := ioutil.ReadFile("./static/index.html")
|
||||||
fmt.Fprintf(w, string(bodyTemplate))
|
fmt.Fprint(w, string(bodyTemplate))
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, pageBuilder(r, "home"))
|
fmt.Fprint(w, pageBuilder(r, "home"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func passPage(w http.ResponseWriter, r *http.Request) {
|
func passPage(w http.ResponseWriter, r *http.Request) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
log.LogInfo(fmt.Sprintf("%s called passPage", getSessionIdentifier(r)))
|
log.LogInfo(fmt.Sprintf("%s called passPage", getSessionIdentifier(r)))
|
||||||
fmt.Fprintf(w, pageBuilder(r, "pass"))
|
fmt.Fprint(w, pageBuilder(r, "pass"))
|
||||||
}
|
}
|
||||||
func loginPage(w http.ResponseWriter, r *http.Request) {
|
func loginPage(w http.ResponseWriter, r *http.Request) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
@ -85,18 +84,18 @@ func loginPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogWarn("Error logging out from loginPage()")
|
log.LogWarn("Error logging out from loginPage()")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, pageBuilder(r, "home"))
|
fmt.Fprint(w, pageBuilder(r, "home"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, pageBuilder(r, "login"))
|
fmt.Fprint(w, pageBuilder(r, "login"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func notFoundPage(w http.ResponseWriter, r *http.Request) {
|
func notFoundPage(w http.ResponseWriter, r *http.Request) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
go log.LogWarn(fmt.Sprintf("%s triggered notFoundPage", getSessionIdentifier(r)))
|
go log.LogWarn(fmt.Sprintf("%s triggered notFoundPage", getSessionIdentifier(r)))
|
||||||
fmt.Fprintf(w, topWrapper(r))
|
fmt.Fprint(w, topWrapper(r))
|
||||||
|
|
||||||
fmt.Fprintf(w, card("Oops! That Page Was Not found.",
|
fmt.Fprint(w, card("Oops! That Page Was Not found.",
|
||||||
"Sorry, a 404 error has occured. The requested page not found! <br><br>"+
|
"Sorry, a 404 error has occured. The requested page not found! <br><br>"+
|
||||||
"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/t3otBjVZzT0\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>",
|
"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/t3otBjVZzT0\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>",
|
||||||
"<div class=\"error-actions\"><a href=\"/\" class=\"btn btn-primary btn-lg\"><span class=\"glyphicon glyphicon-home\"></span>Take Me Home </a> <a href=\"mailto://rudi@nmare.net\" class=\"btn btn-default btn-lg\"><span class=\"glyphicon glyphicon-envelope\"></span> Contact Support </a></div>"))
|
"<div class=\"error-actions\"><a href=\"/\" class=\"btn btn-primary btn-lg\"><span class=\"glyphicon glyphicon-home\"></span>Take Me Home </a> <a href=\"mailto://rudi@nmare.net\" class=\"btn btn-default btn-lg\"><span class=\"glyphicon glyphicon-envelope\"></span> Contact Support </a></div>"))
|
||||||
@ -126,7 +125,7 @@ func getPending(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
notFoundPage(w, r)
|
notFoundPage(w, r)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(pending))
|
fmt.Fprint(w, string(pending))
|
||||||
} else {
|
} else {
|
||||||
notFoundPage(w, r)
|
notFoundPage(w, r)
|
||||||
}
|
}
|
||||||
@ -140,7 +139,7 @@ func getConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
notFoundPage(w, r)
|
notFoundPage(w, r)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(pending))
|
fmt.Fprint(w, string(pending))
|
||||||
} else {
|
} else {
|
||||||
notFoundPage(w, r)
|
notFoundPage(w, r)
|
||||||
}
|
}
|
||||||
@ -154,7 +153,7 @@ func getProbations(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
notFoundPage(w, r)
|
notFoundPage(w, r)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(pending))
|
fmt.Fprint(w, string(pending))
|
||||||
} else {
|
} else {
|
||||||
notFoundPage(w, r)
|
notFoundPage(w, r)
|
||||||
}
|
}
|
||||||
@ -193,7 +192,7 @@ func getVerifications(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(verifications))
|
fmt.Fprint(w, string(verifications))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUser(w http.ResponseWriter, r *http.Request) {
|
func getUser(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -215,16 +214,7 @@ func getUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(ret))
|
fmt.Fprint(w, string(ret))
|
||||||
}
|
|
||||||
|
|
||||||
func getVerification(w http.ResponseWriter, r *http.Request) {
|
|
||||||
loggedIn, _ := detectUser(r, "getVerification")
|
|
||||||
if !loggedIn {
|
|
||||||
notFoundPage(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
http.ServeFile(w, r, r.URL.Path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runWeb() {
|
func runWeb() {
|
||||||
|
|||||||
6
types.go
6
types.go
@ -54,12 +54,6 @@ type Verification struct {
|
|||||||
Closed time.Time
|
Closed time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type linkedAccount struct {
|
|
||||||
domainUser string
|
|
||||||
discordUser string
|
|
||||||
sigHash string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tokens are the Login Token struct
|
// Tokens are the Login Token struct
|
||||||
type Tokens struct {
|
type Tokens struct {
|
||||||
Username string
|
Username string
|
||||||
|
|||||||
Reference in New Issue
Block a user