mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 07:57:21 +08:00
fix: 首页mysql数据库数量不显示
This commit is contained in:
@@ -255,7 +255,7 @@ func (r *backupRepo) createMySQL(to string, name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mysql, err := db.NewMySQL("root", rootPassword, "/tmp/mysql.sock")
|
||||
mysql, err := db.NewMySQL("root", rootPassword, "/tmp/mysql.sock", "unix")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -401,7 +401,7 @@ func (r *backupRepo) restoreMySQL(backup, target string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mysql, err := db.NewMySQL("root", rootPassword, "/tmp/mysql.sock")
|
||||
mysql, err := db.NewMySQL("root", rootPassword, "/tmp/mysql.sock", "unix")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -124,40 +124,18 @@ func (s *DashboardService) CountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
mysqlInstalled, _ := s.appRepo.IsInstalled("slug like ?", "mysql%")
|
||||
postgresqlInstalled, _ := s.appRepo.IsInstalled("slug like ?", "postgresql%")
|
||||
mysqlInstalled, _ := s.appRepo.IsInstalled("slug = ?", "mysql")
|
||||
postgresqlInstalled, _ := s.appRepo.IsInstalled("slug = ?", "postgresql")
|
||||
|
||||
type database struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
var databaseCount int64
|
||||
var databaseCount int
|
||||
if mysqlInstalled {
|
||||
rootPassword, _ := s.settingRepo.Get(biz.SettingKeyMySQLRootPassword)
|
||||
mysql, err := db.NewMySQL("root", rootPassword, "/tmp/mysql.sock")
|
||||
mysql, err := db.NewMySQL("root", rootPassword, "/tmp/mysql.sock", "unix")
|
||||
if err == nil {
|
||||
defer mysql.Close()
|
||||
if err = mysql.Ping(); err != nil {
|
||||
databaseCount = -1
|
||||
} else {
|
||||
rows, err := mysql.Query("SHOW DATABASES")
|
||||
if err != nil {
|
||||
databaseCount = -1
|
||||
} else {
|
||||
defer rows.Close()
|
||||
var databases []database
|
||||
for rows.Next() {
|
||||
var d database
|
||||
if err := rows.Scan(&d.Name); err != nil {
|
||||
continue
|
||||
}
|
||||
if d.Name == "information_schema" || d.Name == "performance_schema" || d.Name == "mysql" || d.Name == "sys" {
|
||||
continue
|
||||
}
|
||||
|
||||
databases = append(databases, d)
|
||||
}
|
||||
databaseCount = int64(len(databases))
|
||||
}
|
||||
databases, err := mysql.Databases()
|
||||
if err == nil {
|
||||
databaseCount += len(databases)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,38 +143,20 @@ func (s *DashboardService) CountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
postgres, err := db.NewPostgres("postgres", "", "127.0.0.1", fmt.Sprintf("%s/server/postgresql/data/pg_hba.conf", app.Root), 5432)
|
||||
if err == nil {
|
||||
defer postgres.Close()
|
||||
if err = postgres.Ping(); err != nil {
|
||||
databaseCount = -1
|
||||
} else {
|
||||
rows, err := postgres.Query("SELECT datname FROM pg_database WHERE datistemplate = false")
|
||||
if err != nil {
|
||||
databaseCount = -1
|
||||
} else {
|
||||
defer rows.Close()
|
||||
var databases []database
|
||||
for rows.Next() {
|
||||
var d database
|
||||
if err = rows.Scan(&d.Name); err != nil {
|
||||
continue
|
||||
}
|
||||
if d.Name == "postgres" || d.Name == "template0" || d.Name == "template1" {
|
||||
continue
|
||||
}
|
||||
databases = append(databases, d)
|
||||
}
|
||||
databaseCount = int64(len(databases))
|
||||
}
|
||||
databases, err := postgres.Databases()
|
||||
if err == nil {
|
||||
databaseCount += len(databases)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ftpCount int64
|
||||
var ftpCount int
|
||||
ftpInstalled, _ := s.appRepo.IsInstalled("slug = ?", "pureftpd")
|
||||
if ftpInstalled {
|
||||
listRaw, err := shell.Execf("pure-pw list")
|
||||
if len(listRaw) != 0 && err == nil {
|
||||
listArr := strings.Split(listRaw, "\n")
|
||||
ftpCount = int64(len(listArr))
|
||||
ftpCount = len(listArr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,8 +174,8 @@ func (s *DashboardService) CountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DashboardService) InstalledDbAndPhp(w http.ResponseWriter, r *http.Request) {
|
||||
mysqlInstalled, _ := s.appRepo.IsInstalled("slug like ?", "mysql%")
|
||||
postgresqlInstalled, _ := s.appRepo.IsInstalled("slug like ?", "postgresql%")
|
||||
mysqlInstalled, _ := s.appRepo.IsInstalled("slug = ?", "mysql")
|
||||
postgresqlInstalled, _ := s.appRepo.IsInstalled("slug = ?", "postgresql")
|
||||
php, _ := s.appRepo.GetInstalledAll("slug like ?", "php%")
|
||||
|
||||
var phpData []types.LVInt
|
||||
|
||||
@@ -3,6 +3,7 @@ package db
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
|
||||
@@ -23,10 +24,10 @@ func NewMySQL(username, password, address string, typ ...string) (*MySQL, error)
|
||||
}
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("初始化MySQL连接失败: %w", err)
|
||||
return nil, fmt.Errorf("init mysql connection failed: %w", err)
|
||||
}
|
||||
if db.Ping() != nil {
|
||||
return nil, fmt.Errorf("连接MySQL失败: %w", err)
|
||||
if err = db.Ping(); err != nil {
|
||||
return nil, fmt.Errorf("connect to mysql failed: %w", err)
|
||||
}
|
||||
return &MySQL{
|
||||
db: db,
|
||||
@@ -168,6 +169,9 @@ func (m *MySQL) Databases() ([]types.MySQLDatabase, error) {
|
||||
if err := rows.Scan(&database); err != nil {
|
||||
continue
|
||||
}
|
||||
if slices.Contains([]string{"information_schema", "performance_schema", "mysql", "sys"}, database) {
|
||||
continue
|
||||
}
|
||||
databases = append(databases, types.MySQLDatabase{
|
||||
Name: database,
|
||||
})
|
||||
|
||||
@@ -28,10 +28,10 @@ func NewPostgres(username, password, address, hbaFile string, port uint) (*Postg
|
||||
}
|
||||
db, err := sql.Open("postgres", dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("初始化Postgres连接失败: %w", err)
|
||||
return nil, fmt.Errorf("init postgres connection failed: %w", err)
|
||||
}
|
||||
if db.Ping() != nil {
|
||||
return nil, fmt.Errorf("连接Postgres失败: %w", err)
|
||||
if err = db.Ping(); err != nil {
|
||||
return nil, fmt.Errorf("connect to postgres failed: %w", err)
|
||||
}
|
||||
return &Postgres{
|
||||
db: db,
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"placeholder": "admin"
|
||||
},
|
||||
"email": {
|
||||
"label": "Email (may be useful later)",
|
||||
"label": "Certificate default email",
|
||||
"placeholder": "admin{'@'}example.com"
|
||||
},
|
||||
"port": {
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"placeholder": "admin"
|
||||
},
|
||||
"email": {
|
||||
"label": "邮箱(以后可能会有用)",
|
||||
"label": "证书默认邮箱",
|
||||
"placeholder": "admin{'@'}example.com"
|
||||
},
|
||||
"port": {
|
||||
|
||||
Reference in New Issue
Block a user