Compare commits

..
5 Commits
Author SHA1 Message Date
github-actions[bot] d65f7ca924 Merge pull request #331 from komari-monitor/dev
fix: 重复注册Bark
2025-10-15 05:14:01 +00:00
Akizon77 a4d95640a5 fix: 重复注册Bark 2025-10-15 13:13:31 +08:00
Akizon77 adda3a2488 docs: 移除Crowdin 2025-10-15 13:09:18 +08:00
github-actions[bot] 34654c0969 Merge pull request #320 from komari-monitor/dev
fix: #319 伪随机 token 可预测
2025-10-09 11:09:44 +00:00
Akizon77 b708f9817d fix: 伪随机 token 可预测 2025-10-09 19:09:11 +08:00
3 changed files with 27 additions and 21 deletions

No files matched your search

-2
View File
@@ -100,8 +100,6 @@ sudo ./install-komari.sh
## Frontend Development Guide
[Komari Theme Development Guide | Komari](https://komari-document.pages.dev/dev/theme.html)
[Translate Komari on Crowdin](https://crowdin.com/project/komari/invite?h=cd051bf172c9a9f7f1360e87ffb521692507706)
## Client Agent Development Guide
[Komari Agent Information Reporting and Event Handling Documentation](https://komari-document.pages.dev/dev/agent.html)
+3 -9
View File
@@ -77,7 +77,7 @@ func (b *BarkSender) SendTextMessage(message, title string) error {
if serverURL == "" {
serverURL = "https://api.day.app"
}
// 确保 URL 以正确的格式结尾
serverURL = strings.TrimRight(serverURL, "/")
requestURL := fmt.Sprintf("%s/push", serverURL)
@@ -96,8 +96,8 @@ func (b *BarkSender) SendTextMessage(message, title string) error {
// 解析响应
var result struct {
Code int `json:"code"`
Message string `json:"message"`
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data"`
}
@@ -114,11 +114,5 @@ func (b *BarkSender) SendTextMessage(message, title string) error {
return nil
}
func init() {
factory.RegisterMessageSender(func() factory.IMessageSender {
return &BarkSender{}
})
}
// 确保实现了 IMessageSender 接口
var _ factory.IMessageSender = (*BarkSender)(nil)
+24 -10
View File
@@ -1,19 +1,33 @@
package utils
import (
"encoding/base64"
"math/rand"
"time"
"crypto/rand"
)
func GenerateRandomString(length int) string {
b := make([]byte, length)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
_, err := r.Read(b)
if err != nil {
if length <= 0 {
return ""
}
return base64.URLEncoding.EncodeToString(b)[:length]
const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
const n = byte(len(charset)) // 62
const threshold = byte(256 - (256 % len(charset))) // 248
out := make([]byte, 0, length)
buf := make([]byte, length)
for len(out) < length {
if _, err := rand.Read(buf); err != nil {
return ""
}
for _, b := range buf {
if b < threshold {
out = append(out, charset[int(b%n)])
if len(out) == length {
break
}
}
}
}
return string(out)
}
func GeneratePassword() string {
@@ -21,5 +35,5 @@ func GeneratePassword() string {
}
func GenerateToken() string {
return GenerateRandomString(16)
}
return GenerateRandomString(22)
}