Files
waf-platform/EdgeUser/internal/utils/portalutils/utils.go

51 lines
900 B
Go

// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package portalutils
import (
"github.com/TeaOSLab/EdgeUser/internal/remotelogs"
"github.com/iwind/TeaGo/Tea"
"io"
"os"
)
func HasPortalIndex() bool {
return len(checkPortalIndex()) > 0
}
func ReadPortalIndex(writer io.Writer) {
var indexPath = checkPortalIndex()
if len(indexPath) == 0 {
return
}
fp, err := os.Open(indexPath)
if err != nil {
remotelogs.Error("PORTAL", "read portal index failed: "+err.Error())
return
}
defer func() {
_ = fp.Close()
}()
_, _ = io.Copy(writer, fp)
}
func checkPortalIndex() string {
var indexes = []string{
"index.html",
}
for _, index := range indexes {
var path = Tea.Root + "/www/" + index
stat, err := os.Stat(path)
if err != nil {
continue
}
if stat.IsDir() {
continue
}
return path
}
return ""
}