Initial commit (code only without large binaries)
This commit is contained in:
60
EdgeUser/internal/web/actions/default/portal/wildcard.go
Normal file
60
EdgeUser/internal/web/actions/default/portal/wildcard.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package portal
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type WildcardAction struct {
|
||||
actionutils.PortalAction
|
||||
}
|
||||
|
||||
func (this *WildcardAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *WildcardAction) RunGet(params struct {
|
||||
Filename string
|
||||
}) {
|
||||
var pieces = strings.Split(params.Filename, "/")
|
||||
var reg = regexp.MustCompile(`^[@\w+.]+$`)
|
||||
for _, piece := range pieces {
|
||||
if !reg.MatchString(piece) {
|
||||
this.ResponseWriter.Header().Set("Content-Type", "text/plain; charset=utf-8") // prevent html injection
|
||||
this.ResponseWriter.WriteHeader(http.StatusBadRequest)
|
||||
this.WriteString("invalid url '" + params.Filename + "'")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// check file
|
||||
var paths = []string{
|
||||
"/portal/" + params.Filename + ".html",
|
||||
"/portal/" + params.Filename + "/index.html",
|
||||
}
|
||||
var foundPath string
|
||||
var found = false
|
||||
for _, path := range paths {
|
||||
_, err := os.Stat(Tea.Root + path)
|
||||
if err == nil {
|
||||
found = true
|
||||
foundPath = path
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
this.ResponseWriter.WriteHeader(http.StatusNotFound)
|
||||
this.WriteString("page not found '" + params.Filename + "'")
|
||||
return
|
||||
}
|
||||
|
||||
this.View(foundPath)
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user