mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-07-19 17:23:33 -05:00
NAS: Return HTTP error codes
This commit is contained in:
parent
8804352d29
commit
6834661ad1
10
nas/auth.go
10
nas/auth.go
|
|
@ -15,6 +15,7 @@ func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request
|
|||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
logging.Error(moduleName, "Failed to parse form")
|
||||
replyHTTPError(w, 400, "400 Bad Request")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -28,6 +29,7 @@ func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request
|
|||
parsed, err := common.Base64DwcEncoding.DecodeString(values[0])
|
||||
if err != nil {
|
||||
logging.Error(moduleName, "Invalid POST form value:", aurora.Cyan(key).String()+":", aurora.Cyan(values[0]))
|
||||
replyHTTPError(w, 400, "400 Bad Request")
|
||||
return
|
||||
}
|
||||
logging.Info(moduleName, aurora.Cyan(key).String()+":", aurora.Cyan(string(parsed)))
|
||||
|
|
@ -37,6 +39,7 @@ func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request
|
|||
action, ok := fields["action"]
|
||||
if !ok || action == "" {
|
||||
logging.Error(moduleName, "No action in form")
|
||||
replyHTTPError(w, 400, "400 Bad Request")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +53,13 @@ func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request
|
|||
case "acctcreate":
|
||||
reply = acctcreate(moduleName, fields)
|
||||
break
|
||||
|
||||
default:
|
||||
reply = map[string]string{
|
||||
"retry": "0",
|
||||
"returncd": "109",
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
param := url.Values{}
|
||||
|
|
|
|||
20
nas/main.go
20
nas/main.go
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/logrusorgru/aurora/v3"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
|
@ -40,7 +39,7 @@ func StartServer() {
|
|||
address := config.Address + ":" + config.Port
|
||||
|
||||
logging.Notice("NAS", "Starting HTTP server on", address)
|
||||
log.Fatal(nhttp.ListenAndServe(address, http.HandlerFunc(handleRequest)))
|
||||
panic(nhttp.ListenAndServe(address, http.HandlerFunc(handleRequest)))
|
||||
}
|
||||
|
||||
var regexSakeHost = regexp.MustCompile(`^([a-z\-]+\.)?sake\.gs\.`)
|
||||
|
|
@ -86,4 +85,21 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||
downloadStage1(moduleName, w, r, val)
|
||||
return
|
||||
}
|
||||
|
||||
replyHTTPError(w, 404, "404 Not Found")
|
||||
}
|
||||
|
||||
func replyHTTPError(w http.ResponseWriter, errorCode int, errorString string) {
|
||||
response := "<html>\n"
|
||||
response += "<head><title>" + errorString + "</title></head>\n"
|
||||
response += "<body>\n"
|
||||
response += "<center><h1>" + errorString + "</h1></center>\n"
|
||||
response += "<hr><center>WiiLink</center>\n"
|
||||
response += "</body>\n"
|
||||
response += "</html>\n"
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
|
||||
w.WriteHeader(errorCode)
|
||||
w.Write([]byte(response))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user