@@ -0,0 +1,51 @@
|
||||
package seoser
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
"videoweb/app/appg"
|
||||
)
|
||||
|
||||
// VerifyCodes 站长平台所有权验证(meta + 根路径文件)。
|
||||
type VerifyCodes struct {
|
||||
Baidu string
|
||||
BaiduHTML string
|
||||
IndexNowKey string
|
||||
}
|
||||
|
||||
// VerifyFromConfig 读取 yaml 中的验证码与验证文件名。
|
||||
func VerifyFromConfig() VerifyCodes {
|
||||
seo := appg.Conf.SEO
|
||||
return VerifyCodes{
|
||||
Baidu: strings.TrimSpace(seo.BaiduSiteVerification),
|
||||
BaiduHTML: sanitizeVerifyFile(seo.BaiduHTMLFile),
|
||||
IndexNowKey: sanitizeIndexNowKey(seo.IndexNowKey),
|
||||
}
|
||||
}
|
||||
|
||||
func sanitizeVerifyFile(raw string) string {
|
||||
raw = strings.TrimSpace(strings.ReplaceAll(raw, "\\", "/"))
|
||||
raw = path.Base(raw)
|
||||
if raw == "" || raw == "." || raw == "/" || strings.Contains(raw, "..") {
|
||||
return ""
|
||||
}
|
||||
lower := strings.ToLower(raw)
|
||||
if strings.HasSuffix(lower, ".html") || strings.HasSuffix(lower, ".htm") || strings.HasSuffix(lower, ".xml") {
|
||||
return raw
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func sanitizeIndexNowKey(raw string) string {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return ""
|
||||
}
|
||||
for _, r := range raw {
|
||||
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '-' || r == '_' {
|
||||
continue
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return raw
|
||||
}
|
||||
Reference in New Issue
Block a user