Initial commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := gorm.Open(sqlite.Open("e:/Project/MeshRay/data/meshray.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("=== MeshRay 数据库表结构检查 ===\n")
|
||||
|
||||
// 检查所有表是否存在
|
||||
tables := []string{
|
||||
"networks",
|
||||
"devices",
|
||||
"policies",
|
||||
"services",
|
||||
"mesh_seeds",
|
||||
"pending_joins",
|
||||
"alert_rules",
|
||||
"audit_logs",
|
||||
"users",
|
||||
"system_configs",
|
||||
"ddns_configs",
|
||||
"network_members",
|
||||
"security_keys",
|
||||
"system_settings",
|
||||
"external_services",
|
||||
"turn_configs", // 这个应该不存在
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
query := fmt.Sprintf("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='%s'", table)
|
||||
var count int64
|
||||
db.Raw(query).Scan(&count)
|
||||
|
||||
if count > 0 {
|
||||
fmt.Printf("✅ %s: 存在\n", table)
|
||||
|
||||
// 显示字段信息
|
||||
showTableSchema(db, table)
|
||||
} else {
|
||||
fmt.Printf("❌ %s: 不存在\n", table)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func showTableSchema(db *gorm.DB, tableName string) {
|
||||
rows, err := db.Raw(fmt.Sprintf("PRAGMA table_info(%s)", tableName)).Rows()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var cid, notnull int
|
||||
var name, typ string
|
||||
var dflt_value interface{}
|
||||
var pk int
|
||||
|
||||
rows.Scan(&cid, &name, &typ, ¬null, &dflt_value, &pk)
|
||||
fmt.Printf(" - %s (%s) [pk=%d, notnull=%d]\n", name, typ, pk, notnull)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// 命令行工具 - 重置管理员密码
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.zkcoi.com/zkcoi/meshray/internal/config"
|
||||
"git.zkcoi.com/zkcoi/meshray/internal/service"
|
||||
store "git.zkcoi.com/zkcoi/meshray/internal/store/sqlite"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// ANSI 颜色代码
|
||||
const (
|
||||
ColorReset = "\033[0m"
|
||||
ColorRed = "\033[31m"
|
||||
ColorGreen = "\033[32m"
|
||||
ColorYellow = "\033[33m"
|
||||
ColorBlue = "\033[34m"
|
||||
)
|
||||
|
||||
var (
|
||||
resetPasswordCmd = &cobra.Command{
|
||||
Use: "reset-admin-password",
|
||||
Short: "重置管理员密码",
|
||||
Long: "重置 MeshRay 管理员账户的密码。将生成随机密码并在控制台显示。",
|
||||
RunE: runResetPassword,
|
||||
}
|
||||
|
||||
newPassword string
|
||||
)
|
||||
|
||||
func init() {
|
||||
resetPasswordCmd.Flags().StringVarP(&newPassword, "new-password", "p", "", "设置新密码(留空则自动生成随机密码)")
|
||||
}
|
||||
|
||||
func runResetPassword(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("MeshRay - 重置管理员密码")
|
||||
fmt.Println("=========================")
|
||||
fmt.Println("")
|
||||
|
||||
// 加载配置
|
||||
cfg, err := config.Load("")
|
||||
if err != nil {
|
||||
return fmt.Errorf("加载配置失败:%w", err)
|
||||
}
|
||||
|
||||
// 确保数据库文件存在
|
||||
if _, err := os.Stat(cfg.Database.Path); os.IsNotExist(err) {
|
||||
return fmt.Errorf("数据库文件不存在:%s", cfg.Database.Path)
|
||||
}
|
||||
|
||||
// 连接数据库
|
||||
dbStore, err := store.New(cfg.Database.Path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("连接数据库失败:%w", err)
|
||||
}
|
||||
defer dbStore.Close()
|
||||
|
||||
// 创建用户服务
|
||||
userService := service.NewUserService(dbStore)
|
||||
|
||||
// 生成或使用指定的新密码
|
||||
finalPassword := newPassword
|
||||
if finalPassword == "" {
|
||||
finalPassword = service.GenerateRandomPassword(16)
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
err = userService.ResetAdminPassword(finalPassword)
|
||||
if err != nil {
|
||||
return fmt.Errorf("重置密码失败:%w", err)
|
||||
}
|
||||
|
||||
// 输出结果
|
||||
fmt.Println("")
|
||||
fmt.Printf("%s========================================%s\n", ColorGreen, ColorReset)
|
||||
fmt.Printf("%s✅ 管理员密码已重置%s\n", ColorGreen, ColorReset)
|
||||
fmt.Printf("%s========================================%s\n", ColorGreen, ColorReset)
|
||||
fmt.Printf("用户名:admin\n")
|
||||
fmt.Printf("新密码:%s%s%s\n", ColorBlue, finalPassword, ColorReset)
|
||||
fmt.Printf("%s****************************************%s\n", ColorYellow, ColorReset)
|
||||
fmt.Printf("%s⚠️ 请妥善保管密码,建议登录后立即修改%s\n", ColorYellow, ColorReset)
|
||||
fmt.Printf("%s****************************************%s\n", ColorYellow, ColorReset)
|
||||
fmt.Println("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := resetPasswordCmd.Execute(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "错误:%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
|
||||
"git.zkcoi.com/zkcoi/meshray/web"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("=== 测试 WebAssets ===")
|
||||
|
||||
count := 0
|
||||
err := fs.WalkDir(web.WebAssets, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, _ := d.Info()
|
||||
fmt.Printf(" %s (%d bytes)\n", path, info.Size())
|
||||
count++
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("错误:%v\n", err)
|
||||
} else {
|
||||
fmt.Printf("\n总共 %d 个文件/目录\n", count)
|
||||
|
||||
// 检查 index.html (此时在 dist 目录下)
|
||||
if _, err := fs.Stat(web.WebAssets, "dist/index.html"); err == nil {
|
||||
fmt.Println("✅ index.html 存在")
|
||||
} else {
|
||||
fmt.Printf("❌ index.html 不存在:%v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user