mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 16:10:59 +08:00
fix: 修正环境检查
This commit is contained in:
@@ -77,9 +77,10 @@ func initWeb() (*app.Web, error) {
|
||||
certAccountRepo := data.NewCertAccountRepo(locale, db, userRepo, logger)
|
||||
settingRepo := data.NewSettingRepo(locale, db, config, taskRepo)
|
||||
websiteRepo := data.NewWebsiteRepo(locale, db, cacheRepo, databaseRepo, databaseServerRepo, databaseUserRepo, certRepo, certAccountRepo, settingRepo)
|
||||
environmentRepo := data.NewEnvironmentRepo(locale, config, cacheRepo, taskRepo)
|
||||
cronRepo := data.NewCronRepo(locale, db)
|
||||
backupRepo := data.NewBackupRepo(locale, db, settingRepo, websiteRepo)
|
||||
homeService := service.NewHomeService(locale, config, taskRepo, websiteRepo, appRepo, settingRepo, cronRepo, backupRepo)
|
||||
homeService := service.NewHomeService(locale, config, taskRepo, websiteRepo, appRepo, environmentRepo, settingRepo, cronRepo, backupRepo)
|
||||
taskService := service.NewTaskService(taskRepo)
|
||||
websiteService := service.NewWebsiteService(websiteRepo, settingRepo)
|
||||
databaseService := service.NewDatabaseService(databaseRepo)
|
||||
@@ -91,7 +92,6 @@ func initWeb() (*app.Web, error) {
|
||||
certDNSService := service.NewCertDNSService(certDNSRepo)
|
||||
certAccountService := service.NewCertAccountService(certAccountRepo)
|
||||
appService := service.NewAppService(locale, appRepo, cacheRepo, settingRepo)
|
||||
environmentRepo := data.NewEnvironmentRepo(locale, config, cacheRepo, taskRepo)
|
||||
environmentService := service.NewEnvironmentService(locale, environmentRepo, taskRepo)
|
||||
environmentPHPService := service.NewEnvironmentPHPService(locale, environmentRepo, taskRepo)
|
||||
cronService := service.NewCronService(cronRepo)
|
||||
|
||||
@@ -27,7 +27,7 @@ type AppRepo interface {
|
||||
GetInstalled(slug string) (*App, error)
|
||||
GetInstalledAll(query string, cond ...string) ([]*App, error)
|
||||
GetHomeShow() ([]map[string]string, error)
|
||||
IsInstalled(query string, cond ...string) (bool, error)
|
||||
IsInstalled(query string, cond ...any) (bool, error)
|
||||
Install(channel, slug string) error
|
||||
UnInstall(slug string) error
|
||||
Update(slug string) error
|
||||
|
||||
@@ -9,6 +9,7 @@ type EnvironmentRepo interface {
|
||||
Types() []types.LV
|
||||
All(typ ...string) api.Environments
|
||||
IsInstalled(typ, slug string) bool
|
||||
InstalledSlugs(typ string) []string
|
||||
InstalledVersion(typ, slug string) string
|
||||
HasUpdate(typ, slug string) bool
|
||||
Install(typ, slug string) error
|
||||
|
||||
@@ -162,14 +162,14 @@ func (r *appRepo) GetHomeShow() ([]map[string]string, error) {
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func (r *appRepo) IsInstalled(query string, cond ...string) (bool, error) {
|
||||
func (r *appRepo) IsInstalled(query string, cond ...any) (bool, error) {
|
||||
var count int64
|
||||
if len(cond) == 0 {
|
||||
if err := r.db.Model(&biz.App{}).Where("slug = ?", query).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
} else {
|
||||
if err := r.db.Model(&biz.App{}).Where(query, cond).Count(&count).Error; err != nil {
|
||||
if err := r.db.Model(&biz.App{}).Where(query, cond...).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,20 @@ func (r *environmentRepo) IsInstalled(typ, slug string) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (r *environmentRepo) InstalledSlugs(typ string) []string {
|
||||
var slugs []string
|
||||
all := r.All()
|
||||
for _, env := range all {
|
||||
if env.Type != typ {
|
||||
continue
|
||||
}
|
||||
if r.IsInstalled(typ, env.Slug) {
|
||||
slugs = append(slugs, env.Slug)
|
||||
}
|
||||
}
|
||||
return slugs
|
||||
}
|
||||
|
||||
func (r *environmentRepo) InstalledVersion(typ, slug string) string {
|
||||
if !r.IsInstalled(typ, slug) {
|
||||
return ""
|
||||
|
||||
@@ -167,7 +167,7 @@ func (route *Http) Register(r *chi.Mux) {
|
||||
r.Post("/current", route.home.Current)
|
||||
r.Get("/system_info", route.home.SystemInfo)
|
||||
r.Get("/count_info", route.home.CountInfo)
|
||||
r.Get("/installed_db_and_php", route.home.InstalledDbAndPhp)
|
||||
r.Get("/installed_environment", route.home.InstalledEnvironment)
|
||||
r.Get("/check_update", route.home.CheckUpdate)
|
||||
r.Get("/update_info", route.home.UpdateInfo)
|
||||
r.Post("/update", route.home.Update)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
@@ -27,28 +26,30 @@ import (
|
||||
)
|
||||
|
||||
type HomeService struct {
|
||||
t *gotext.Locale
|
||||
api *api.API
|
||||
conf *config.Config
|
||||
taskRepo biz.TaskRepo
|
||||
websiteRepo biz.WebsiteRepo
|
||||
appRepo biz.AppRepo
|
||||
settingRepo biz.SettingRepo
|
||||
cronRepo biz.CronRepo
|
||||
backupRepo biz.BackupRepo
|
||||
t *gotext.Locale
|
||||
api *api.API
|
||||
conf *config.Config
|
||||
taskRepo biz.TaskRepo
|
||||
websiteRepo biz.WebsiteRepo
|
||||
appRepo biz.AppRepo
|
||||
environmentRepo biz.EnvironmentRepo
|
||||
settingRepo biz.SettingRepo
|
||||
cronRepo biz.CronRepo
|
||||
backupRepo biz.BackupRepo
|
||||
}
|
||||
|
||||
func NewHomeService(t *gotext.Locale, conf *config.Config, task biz.TaskRepo, website biz.WebsiteRepo, appRepo biz.AppRepo, setting biz.SettingRepo, cron biz.CronRepo, backupRepo biz.BackupRepo) *HomeService {
|
||||
func NewHomeService(t *gotext.Locale, conf *config.Config, task biz.TaskRepo, website biz.WebsiteRepo, appRepo biz.AppRepo, environment biz.EnvironmentRepo, setting biz.SettingRepo, cron biz.CronRepo, backupRepo biz.BackupRepo) *HomeService {
|
||||
return &HomeService{
|
||||
t: t,
|
||||
api: api.NewAPI(app.Version, app.Locale),
|
||||
conf: conf,
|
||||
taskRepo: task,
|
||||
websiteRepo: website,
|
||||
appRepo: appRepo,
|
||||
settingRepo: setting,
|
||||
cronRepo: cron,
|
||||
backupRepo: backupRepo,
|
||||
t: t,
|
||||
api: api.NewAPI(app.Version, app.Locale),
|
||||
conf: conf,
|
||||
taskRepo: task,
|
||||
websiteRepo: website,
|
||||
appRepo: appRepo,
|
||||
environmentRepo: environment,
|
||||
settingRepo: setting,
|
||||
cronRepo: cron,
|
||||
backupRepo: backupRepo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,24 +191,17 @@ func (s *HomeService) CountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *HomeService) InstalledDbAndPhp(w http.ResponseWriter, r *http.Request) {
|
||||
mysqlInstalled, _ := s.appRepo.IsInstalled("slug = ?", "mysql")
|
||||
func (s *HomeService) InstalledEnvironment(w http.ResponseWriter, r *http.Request) {
|
||||
mysqlInstalled, _ := s.appRepo.IsInstalled("slug IN ?", []string{"mysql", "mariadb", "percona"})
|
||||
postgresqlInstalled, _ := s.appRepo.IsInstalled("slug = ?", "postgresql")
|
||||
php, _ := s.appRepo.GetInstalledAll("slug like ?", "php%")
|
||||
|
||||
var phpData []types.LVInt
|
||||
var dbData []types.LV
|
||||
phpData = append(phpData, types.LVInt{Value: 0, Label: s.t.Get("Not used")})
|
||||
dbData = append(dbData, types.LV{Value: "0", Label: s.t.Get("Not used")})
|
||||
for _, p := range php {
|
||||
// 过滤 phpmyadmin
|
||||
match := regexp.MustCompile(`php(\d+)`).FindStringSubmatch(p.Slug)
|
||||
if len(match) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
item, _ := s.appRepo.Get(p.Slug)
|
||||
phpData = append(phpData, types.LVInt{Value: cast.ToInt(strings.ReplaceAll(p.Slug, "php", "")), Label: item.Name})
|
||||
for _, slug := range s.environmentRepo.InstalledSlugs("php") {
|
||||
ver := s.environmentRepo.InstalledVersion("php", slug)
|
||||
phpData = append(phpData, types.LVInt{Value: cast.ToInt(slug), Label: fmt.Sprintf("PHP %s", ver)})
|
||||
}
|
||||
|
||||
if mysqlInstalled {
|
||||
@@ -217,9 +211,11 @@ func (s *HomeService) InstalledDbAndPhp(w http.ResponseWriter, r *http.Request)
|
||||
dbData = append(dbData, types.LV{Value: "postgresql", Label: "PostgreSQL"})
|
||||
}
|
||||
|
||||
webserver, _ := s.settingRepo.Get(biz.SettingKeyWebserver)
|
||||
Success(w, chix.M{
|
||||
"php": phpData,
|
||||
"db": dbData,
|
||||
"webserver": webserver,
|
||||
"php": phpData,
|
||||
"db": dbData,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +132,11 @@ func (v *baseVhost) SetEnable(enable bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 清理保存的根目录文件
|
||||
if enable {
|
||||
_ = os.RemoveAll(filepath.Join(v.configDir, "root.saved"))
|
||||
}
|
||||
|
||||
// 设置 Include 配置
|
||||
v.vhost.RemoveDirectives("IncludeOptional")
|
||||
if enable {
|
||||
|
||||
@@ -135,6 +135,11 @@ func (v *baseVhost) SetEnable(enable bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 清理保存的根目录文件
|
||||
if enable {
|
||||
_ = os.RemoveAll(filepath.Join(v.configDir, "root.saved"))
|
||||
}
|
||||
|
||||
// 设置导入配置
|
||||
_ = v.parser.Clear("server.include")
|
||||
if enable {
|
||||
|
||||
@@ -12,8 +12,8 @@ export default {
|
||||
systemInfo: (): any => http.Get('/home/system_info'),
|
||||
// 统计信息
|
||||
countInfo: (): any => http.Get('/home/count_info'),
|
||||
// 已安装的数据库和PHP
|
||||
installedDbAndPhp: (): any => http.Get('/home/installed_db_and_php'),
|
||||
// 已安装的环境
|
||||
installedEnvironment: (): any => http.Get('/home/installed_environment'),
|
||||
// 检查更新
|
||||
checkUpdate: (): any => http.Get('/home/check_update'),
|
||||
// 更新日志
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useGettext } from 'vue3-gettext'
|
||||
const { $gettext } = useGettext()
|
||||
const currentTab = ref('website')
|
||||
|
||||
const { data: installedDbAndPhp } = useRequest(home.installedDbAndPhp, {
|
||||
const { data: installedEnvironment } = useRequest(home.installedEnvironment, {
|
||||
initialData: {
|
||||
db: [
|
||||
{
|
||||
@@ -22,11 +22,11 @@ const { data: installedDbAndPhp } = useRequest(home.installedDbAndPhp, {
|
||||
})
|
||||
|
||||
const mySQLInstalled = computed(() => {
|
||||
return installedDbAndPhp.value.db.find((item: any) => item.value === 'mysql')
|
||||
return installedEnvironment.value.db.find((item: any) => item.value === 'mysql')
|
||||
})
|
||||
|
||||
const postgreSQLInstalled = computed(() => {
|
||||
return installedDbAndPhp.value.db.find((item: any) => item.value === 'postgresql')
|
||||
return installedEnvironment.value.db.find((item: any) => item.value === 'postgresql')
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ const createModel = ref({
|
||||
|
||||
const websites = ref<any>([])
|
||||
|
||||
const { data: installedDbAndPhp } = useRequest(home.installedDbAndPhp, {
|
||||
const { data: installedEnvironment } = useRequest(home.installedEnvironment, {
|
||||
initialData: {
|
||||
db: [
|
||||
{
|
||||
@@ -36,11 +36,11 @@ const { data: installedDbAndPhp } = useRequest(home.installedDbAndPhp, {
|
||||
})
|
||||
|
||||
const mySQLInstalled = computed(() => {
|
||||
return installedDbAndPhp.value.db.find((item: any) => item.value === 'mysql')
|
||||
return installedEnvironment.value.db.find((item: any) => item.value === 'mysql')
|
||||
})
|
||||
|
||||
const postgreSQLInstalled = computed(() => {
|
||||
return installedDbAndPhp.value.db.find((item: any) => item.value === 'postgresql')
|
||||
return installedEnvironment.value.db.find((item: any) => item.value === 'postgresql')
|
||||
})
|
||||
|
||||
const handleSubmit = async () => {
|
||||
|
||||
@@ -28,7 +28,7 @@ const createModel = ref({
|
||||
proxy: ''
|
||||
})
|
||||
|
||||
const { data: installedDbAndPhp } = useRequest(home.installedDbAndPhp, {
|
||||
const { data: installedEnvironment } = useRequest(home.installedEnvironment, {
|
||||
initialData: {
|
||||
php: [
|
||||
{
|
||||
@@ -141,7 +141,7 @@ const formatDbValue = (value: string) => {
|
||||
<n-form-item path="php" :label="$gettext('PHP Version')">
|
||||
<n-select
|
||||
v-model:value="createModel.php"
|
||||
:options="installedDbAndPhp.php"
|
||||
:options="installedEnvironment.php"
|
||||
:placeholder="$gettext('Select PHP Version')"
|
||||
@keydown.enter.prevent
|
||||
>
|
||||
@@ -153,7 +153,7 @@ const formatDbValue = (value: string) => {
|
||||
<n-form-item path="db" :label="$gettext('Database')">
|
||||
<n-select
|
||||
v-model:value="createModel.db_type"
|
||||
:options="installedDbAndPhp.db"
|
||||
:options="installedEnvironment.db"
|
||||
:placeholder="$gettext('Select Database')"
|
||||
@keydown.enter.prevent
|
||||
@update:value="
|
||||
|
||||
@@ -49,7 +49,7 @@ const { data: setting, send: fetchSetting } = useRequest(website.config(Number(i
|
||||
proxies: []
|
||||
}
|
||||
})
|
||||
const { data: installedDbAndPhp } = useRequest(home.installedDbAndPhp, {
|
||||
const { data: installedEnvironment } = useRequest(home.installedEnvironment, {
|
||||
initialData: {
|
||||
php: [
|
||||
{
|
||||
@@ -249,7 +249,7 @@ const hasArg = (args: string[], arg: string) => {
|
||||
<n-select
|
||||
v-model:value="setting.php"
|
||||
:default-value="0"
|
||||
:options="installedDbAndPhp.php"
|
||||
:options="installedEnvironment.php"
|
||||
:placeholder="$gettext('Select PHP Version')"
|
||||
@keydown.enter.prevent
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user